From 2753611be8b4aefdef5086ea32dfa679887298f5 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Fri, 29 Mar 2024 01:56:25 +0400 Subject: [PATCH] refactor(schemas): update JSON Schema Validation Keywords for Arrays --- .../java/com/asyncapi/v3/schema/Schema.java | 173 ++++++++++-------- 1 file changed, 96 insertions(+), 77 deletions(-) diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/Schema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/Schema.java index 092d1227..b916f269 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/Schema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/Schema.java @@ -256,6 +256,102 @@ Validation Keywords for Numeric Instances (number and integer) @JsonProperty("pattern") public String pattern; + /* + Validation Keywords for Arrays + */ + + /** + * The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas. + *

+ * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself. + *

+ * If "items" is a schema, validation succeeds if all elements in the array successfully validate against that schema. + *

+ * If "items" is an array of schemas, validation succeeds if each element of the instance validates against the schema at the same + * position, if any. + *

+ * Omitting this keyword has the same behavior as an empty schema. + * + * @see items + */ + @Nullable + @JsonProperty("items") + @JsonDeserialize(using = SchemaItemsDeserializer.class) + public Object items; + + /** + * The value of "additionalItems" MUST be a valid JSON Schema. + *

+ * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself. + *

+ * If "items" is an array of schemas, validation succeeds if every instance element at a position greater than the size of "items" + * validates against "additionalItems". + *

+ * Otherwise, "additionalItems" MUST be ignored, as the "items" schema (possibly the default value of an empty schema) is applied + * to all elements. + *

+ * Omitting this keyword has the same behavior as an empty schema. + * + * @see additionalItems + */ + @Nullable + @JsonProperty("additionalItems") + public Schema additionalItems; + + /** + * The value of this keyword MUST be a non-negative integer. + *

+ * An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword. + * + * @see maxItems + */ + @Nullable + @Min( + value = 0, + message = "The value of \"maxItems\" MUST be a non-negative integer." + ) + @JsonProperty("maxItems") + public Integer maxItems; + + /** + * The value of this keyword MUST be a non-negative integer. + *

+ * An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword. + *

+ * Omitting this keyword has the same behavior as a value of 0. + * + * @see minItems + */ + @Nullable + @JsonProperty("minItems") + public Integer minItems; + + /** + * The value of this keyword MUST be a boolean. + *

+ * If this keyword has boolean value false, the instance validates successfully. + *

+ * If it has boolean value true, the instance validates successfully if all of its elements are unique. + *

+ * Omitting this keyword has the same behavior as a value of false. + * + * @see uniqueItems + */ + @Nullable + @JsonProperty("uniqueItems") + public Boolean uniqueItems; + + /** + * The value of this keyword MUST be a valid JSON Schema. + *
+ * An array instance is valid against "contains" if at least one of its elements is valid against the given schema. + * + * @see contains + */ + @Nullable + @JsonProperty("contains") + public Schema contains; + /* Schema Annotations @@ -429,83 +525,6 @@ as assertions (Section 3.2). While no special effort is required to Validation. */ - /* - Validation Keywords for Arrays - */ - - /** - * The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas. - *
- * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself. - *
- * If "items" is a schema, validation succeeds if all elements in the array successfully validate against that schema. - *
- * If "items" is an array of schemas, validation succeeds if each element of the instance validates against the schema at the same - * position, if any. - *
- * Omitting this keyword has the same behavior as an empty schema. - */ - @Nullable - @JsonDeserialize(using = SchemaItemsDeserializer.class) - public Object items; - - /** - * The value of "additionalItems" MUST be a valid JSON Schema. - *
- * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself. - *
- * If "items" is an array of schemas, validation succeeds if every instance element at a position greater than the size of "items" - * validates against "additionalItems". - *
- * Otherwise, "additionalItems" MUST be ignored, as the "items" schema (possibly the default value of an empty schema) is applied - * to all elements. - *
- * Omitting this keyword has the same behavior as an empty schema. - */ - @Nullable - public Schema additionalItems; - - /** - * The value of this keyword MUST be a non-negative integer. - *
- * An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword. - */ - @Nullable - @JsonProperty - public Integer maxItems; - - /** - * The value of this keyword MUST be a non-negative integer. - *
- * An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword. - *
- * Omitting this keyword has the same behavior as a value of 0. - */ - @Nullable - @JsonProperty - public Integer minItems; - - /** - * The value of this keyword MUST be a boolean. - *
- * If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, - * the instance validates successfully if all of its elements are unique. - *
- * Omitting this keyword has the same behavior as a value of false. - */ - @Nullable - @JsonProperty - public Boolean uniqueItems; - - /** - * The value of this keyword MUST be a valid JSON Schema. - *
- * An array instance is valid against "contains" if at least one of its elements is valid against the given schema. - */ - @Nullable - @JsonProperty - public Schema contains; - /* Validation Keywords for Objects */