Skip to content

Commit

Permalink
add non-empty check for multi-subschema keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsdennis committed Mar 25, 2024
1 parent 441f9d5 commit dad59b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions JsonSchema/AllOfKeyword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class AllOfKeyword : IJsonSchemaKeyword, ISchemaCollector
/// <param name="values">The set of schemas.</param>
public AllOfKeyword(params JsonSchema[] values)
{
if (values.Length == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");

Schemas = values.ToReadOnlyList() ?? throw new ArgumentNullException(nameof(values));
}

Expand All @@ -49,6 +52,9 @@ public AllOfKeyword(params JsonSchema[] values)
public AllOfKeyword(IEnumerable<JsonSchema> values)
{
Schemas = values.ToReadOnlyList() ?? throw new ArgumentNullException(nameof(values));

if (Schemas.Count == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions JsonSchema/AnyOfKeyword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class AnyOfKeyword : IJsonSchemaKeyword, ISchemaCollector
/// <param name="values">The set of schemas.</param>
public AnyOfKeyword(params JsonSchema[] values)
{
if (values.Length == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");

Schemas = values.ToReadOnlyList() ?? throw new ArgumentNullException(nameof(values));
}

Expand All @@ -49,6 +52,9 @@ public AnyOfKeyword(params JsonSchema[] values)
public AnyOfKeyword(IEnumerable<JsonSchema> values)
{
Schemas = values.ToReadOnlyList() ?? throw new ArgumentNullException(nameof(values));

if (Schemas.Count == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions JsonSchema/OneOfKeyword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class OneOfKeyword : IJsonSchemaKeyword, ISchemaCollector
/// <param name="values">The keywords schema collection.</param>
public OneOfKeyword(params JsonSchema[] values)
{
if (values.Length == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");

Schemas = values.ToReadOnlyList() ?? throw new ArgumentNullException(nameof(values));
}

Expand All @@ -50,6 +53,9 @@ public OneOfKeyword(params JsonSchema[] values)
public OneOfKeyword(IEnumerable<JsonSchema> values)
{
Schemas = values.ToReadOnlyList();

if (Schemas.Count == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions JsonSchema/PrefixItemsKeyword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class PrefixItemsKeyword : IJsonSchemaKeyword, ISchemaCollector
/// </remarks>
public PrefixItemsKeyword(params JsonSchema[] values)
{
if (values.Length == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");

ArraySchemas = values.ToReadOnlyList();
}

Expand All @@ -52,6 +55,9 @@ public PrefixItemsKeyword(params JsonSchema[] values)
public PrefixItemsKeyword(IEnumerable<JsonSchema> values)
{
ArraySchemas = values.ToReadOnlyList();

if (ArraySchemas.Count == 0)
throw new ArgumentException($"'{Name}' requires at least one subschema");
}

/// <summary>
Expand Down

0 comments on commit dad59b7

Please sign in to comment.