-
public interface JsonSchemaBuilderA builder interface for building a JSON schema programmatically.Instances of this type can be created by the factory class
JsonSchemaBuilderFactory.The following code sample shows how to build a JSON schema using this builder.
JsonValidationService service = JsonValidationService.newInstance(); JsonSchemaBuilderFactory factory = service.createSchemaBuilderFactory(); JsonSchemaBuilder builder = factory.createBuilder(); JsonSchema schema = builder .withType(InstanceType.OBJECT) .withProperty("firstName", factory.createBuilder().withType(InstanceType.STRING).build()) .withProperty("lastName", factory.createBuilder().withType(InstanceType.STRING).build()) .withProperty("age", factory.createBuilder() .withType(InstanceType.INTEGER) .withMinimum(0) .build()) .withRequired("firstName", "lastName") .build();For more information about the keywords composing the JSON schema, please see JSON Schema Specification.
Each instance of this type is NOT safe for use by multiple concurrent threads.
- Author:
- leadpony
- See Also:
- JSON Schema Specification
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description JsonSchemabuild()Builds a new instance ofJsonSchema.JsonSchemaBuilderwithAdditionalItems(JsonSchema subschema)Adds an "additionalItems" keyword to the schema.JsonSchemaBuilderwithAdditionalProperties(JsonSchema subschema)Adds an "additionalProperties" keyword to the schema.JsonSchemaBuilderwithAllOf(List<JsonSchema> subschemas)Adds an "allOf" keyword to the schema.JsonSchemaBuilderwithAllOf(JsonSchema... subschemas)Adds an "allOf" keyword to the schema.JsonSchemaBuilderwithAnyOf(List<JsonSchema> subschemas)Adds an "anyOf" keyword to the schema.JsonSchemaBuilderwithAnyOf(JsonSchema... subschemas)Adds an "anyOf" keyword to the schema.JsonSchemaBuilderwithComment(String comment)Adds a "$comment" keyword to the schema.JsonSchemaBuilderwithConst(JsonValue value)Adds a "const" keyword to the schema.JsonSchemaBuilderwithContains(JsonSchema subschema)Adds a "contains" keyword to the schema.JsonSchemaBuilderwithContentEncoding(String value)Adds a "contentEncoding" keyword to the schema.JsonSchemaBuilderwithContentMediaType(String value)Adds a "contentMediaType" keyword to the schema.JsonSchemaBuilderwithDefault(JsonValue value)Adds a "default" keyword to the schema.JsonSchemaBuilderwithDefinition(String name, JsonSchema schema)Adds an entry of "definitions" keyword to the schema.JsonSchemaBuilderwithDefinitions(Map<String,JsonSchema> schemas)Adds a "definitions" keyword to the schema.JsonSchemaBuilderwithDependencies(Map<String,?> values)Adds a "dependencies" keyword to the schema.JsonSchemaBuilderwithDependency(String name, String... requiredProperties)Adds an entry of the "dependencies" keyword to the schema.JsonSchemaBuilderwithDependency(String name, Set<String> requiredProperties)Adds an entry of the "dependencies" keyword to the schema.JsonSchemaBuilderwithDependency(String name, JsonSchema subschema)Adds an entry of the "dependencies" keyword to the schema.JsonSchemaBuilderwithDescription(String description)Adds a "description" keyword to the schema.JsonSchemaBuilderwithElse(JsonSchema subschema)Adds an "else" keyword to the schema.JsonSchemaBuilderwithEnum(Set<JsonValue> values)Adds an "enum" keyword to the schema.JsonSchemaBuilderwithEnum(JsonValue... values)Adds an "enum" keyword to the schema.default JsonSchemaBuilderwithExclusiveMaximum(double value)Adds an "exclusiveMaximum" keyword to the schema.default JsonSchemaBuilderwithExclusiveMaximum(long value)Adds an "exclusiveMaximum" keyword to the schema.JsonSchemaBuilderwithExclusiveMaximum(BigDecimal value)Adds an "exclusiveMaximum" keyword to the schema.default JsonSchemaBuilderwithExclusiveMinimum(double value)Adds an "exclusiveMinimum" keyword to the schema.default JsonSchemaBuilderwithExclusiveMinimum(long value)Adds an "exclusiveMinimum" keyword to the schema.JsonSchemaBuilderwithExclusiveMinimum(BigDecimal value)Adds an "exclusiveMinimum" keyword to the schema.JsonSchemaBuilderwithFormat(String attribute)Adds a "format" keyword to the schema.JsonSchemaBuilderwithId(URI id)Adds a "$id" keyword to the schema.JsonSchemaBuilderwithIf(JsonSchema subschema)Adds an "if" keyword to the schema.JsonSchemaBuilderwithItems(JsonSchema subschema)Adds an "items" keyword to the schema.JsonSchemaBuilderwithItemsArray(List<JsonSchema> subschemas)Adds an "items" keyword to the schema.JsonSchemaBuilderwithItemsArray(JsonSchema... subschemas)Adds an "items" keyword to the schema.JsonSchemaBuilderwithLaxFormat(String attribute)Adds a "format" keyword to the schema.JsonSchemaBuilderwithMaxContains(int value)Adds a "maxContains" keyword to the schema.default JsonSchemaBuilderwithMaximum(double value)Adds a "maximum" keyword to the schema.default JsonSchemaBuilderwithMaximum(long value)Adds a "maximum" keyword to the schema.JsonSchemaBuilderwithMaximum(BigDecimal value)Adds a "maximum" keyword to the schema.JsonSchemaBuilderwithMaxItems(int value)Adds a "maxItems" keyword to the schema.JsonSchemaBuilderwithMaxLength(int value)Adds a "maxLength" keyword to the schema.JsonSchemaBuilderwithMaxProperties(int value)Adds a "maxProperties" keyword to the schema.JsonSchemaBuilderwithMinContains(int value)Adds a "minContains" keyword to the schema.default JsonSchemaBuilderwithMinimum(double value)Adds a "minimum" keyword to the schema.default JsonSchemaBuilderwithMinimum(long value)Adds a "minimum" keyword to the schema.JsonSchemaBuilderwithMinimum(BigDecimal value)Adds a "minimum" keyword to the schema.JsonSchemaBuilderwithMinItems(int value)Adds a "minItems" keyword to the schema.JsonSchemaBuilderwithMinLength(int value)Adds a "minLength" keyword to the schema.JsonSchemaBuilderwithMinProperties(int value)Adds a "minProperties" keyword to the schema.JsonSchemaBuilderwithMultipleOf(double value)Adds a "multipleOf" keyword to the schema.JsonSchemaBuilderwithMultipleOf(long value)Adds a "multipleOf" keyword to the schema.JsonSchemaBuilderwithMultipleOf(BigDecimal value)Adds a "multipleOf" keyword to the schema.JsonSchemaBuilderwithNot(JsonSchema subschema)Adds a "not" keyword to the schema.JsonSchemaBuilderwithOneOf(List<JsonSchema> subschemas)Adds a "oneOf" keyword to the schema.JsonSchemaBuilderwithOneOf(JsonSchema... subschemas)Adds a "oneOf" keyword to the schema.JsonSchemaBuilderwithPattern(String pattern)Adds a "pattern" keyword to the schema.JsonSchemaBuilderwithPatternProperties(Map<String,JsonSchema> subschemas)Adds a "patternProperties" keyword to the schema.JsonSchemaBuilderwithPatternProperty(String pattern, JsonSchema subschema)Adds an entry of the "patternProperties" keyword to the schema.JsonSchemaBuilderwithProperties(Map<String,JsonSchema> subschemas)Adds a "properties" keyword to the schema.JsonSchemaBuilderwithProperty(String name, JsonSchema subschema)Adds an entry of the "properties" keyword to the schema.JsonSchemaBuilderwithPropertyNames(JsonSchema subschema)Adds a "propertyNames" keyword to the schema.JsonSchemaBuilderwithRequired(String... names)Adds a "required" keyword to the schema.JsonSchemaBuilderwithRequired(Set<String> names)Adds a "required" keyword to the schema.JsonSchemaBuilderwithSchema(URI schema)Adds a "$schema" keyword to the schema.JsonSchemaBuilderwithThen(JsonSchema subschema)Adds a "then" keyword to the schema.JsonSchemaBuilderwithTitle(String title)Adds a "title" keyword to the schema.JsonSchemaBuilderwithType(Set<InstanceType> types)Adds a "type" keyword to the schema.JsonSchemaBuilderwithType(InstanceType... types)Adds a "type" keyword to the schema.JsonSchemaBuilderwithUniqueItems(boolean unique)Adds a "uniqueItems" keyword to the schema.
-
-
-
Method Detail
-
build
JsonSchema build()
Builds a new instance ofJsonSchema.- Returns:
- newly created instance of
JsonSchema, never benull.
-
withId
JsonSchemaBuilder withId(URI id)
Adds a "$id" keyword to the schema.- Parameters:
id- the identifier of the schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedidisnull.
-
withSchema
JsonSchemaBuilder withSchema(URI schema)
Adds a "$schema" keyword to the schema.The "$schema" keyword should be used in a root schema. It must not appear in subschemas.
- Parameters:
schema- the version identifier of the schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedschemaisnull.
-
withComment
JsonSchemaBuilder withComment(String comment)
Adds a "$comment" keyword to the schema.- Parameters:
comment- the comment for the schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedcommentisnull.
-
withType
JsonSchemaBuilder withType(InstanceType... types)
Adds a "type" keyword to the schema. The type are specified as an array.- Parameters:
types- the array of types. At least one element is needed and elements must be unique.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedtypesisnull.IllegalArgumentException- if the specifiedtypesis empty, or some types are not unique.
-
withType
JsonSchemaBuilder withType(Set<InstanceType> types)
Adds a "type" keyword to the schema. The type are specified as a set.- Parameters:
types- the set of types. At least one element is needed.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedtypesisnull.IllegalArgumentException- if the specifiedtypesis empty.
-
withEnum
JsonSchemaBuilder withEnum(JsonValue... values)
Adds an "enum" keyword to the schema. The values are specified as an array.- Parameters:
values- the values in the enumeration. At least one element is needed and elements must be unique.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvaluesisnull.IllegalArgumentException- if the specifiedvaluesis empty. or some values are not unique.
-
withEnum
JsonSchemaBuilder withEnum(Set<JsonValue> values)
Adds an "enum" keyword to the schema. The values are specified as a set.- Parameters:
values- the values in the enumeration. At least one element is needed.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvaluesisnull.IllegalArgumentException- if the specifiedvaluesis empty.
-
withConst
JsonSchemaBuilder withConst(JsonValue value)
Adds a "const" keyword to the schema.- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withMultipleOf
JsonSchemaBuilder withMultipleOf(long value)
Adds a "multipleOf" keyword to the schema. The value is specified as long type.- Parameters:
value- the value of the keyword. This must be greater than 0.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis not greater than 0.
-
withMultipleOf
JsonSchemaBuilder withMultipleOf(double value)
Adds a "multipleOf" keyword to the schema. The value is specified as double type.- Parameters:
value- the value of the keyword. This must be greater than 0.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis not greater than 0.
-
withMultipleOf
JsonSchemaBuilder withMultipleOf(BigDecimal value)
Adds a "multipleOf" keyword to the schema. The value is specified asBigDecimaltype.- Parameters:
value- the value of the keyword. This must be greater than 0.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.IllegalArgumentException- if the specifiedvalueis not greater than 0.
-
withMaximum
default JsonSchemaBuilder withMaximum(long value)
Adds a "maximum" keyword to the schema. The value is specified as long type.This keyword specifies an inclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withMaximum
default JsonSchemaBuilder withMaximum(double value)
Adds a "maximum" keyword to the schema. The value is specified as double type.This keyword specifies an inclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withMaximum
JsonSchemaBuilder withMaximum(BigDecimal value)
Adds a "maximum" keyword to the schema. The value is specified asBigDecimaltype.This keyword specifies an inclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withExclusiveMaximum
default JsonSchemaBuilder withExclusiveMaximum(long value)
Adds an "exclusiveMaximum" keyword to the schema. The value is specified as long type.This keyword specifies an exclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withExclusiveMaximum
default JsonSchemaBuilder withExclusiveMaximum(double value)
Adds an "exclusiveMaximum" keyword to the schema. The value is specified as double type.This keyword specifies an exclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withExclusiveMaximum
JsonSchemaBuilder withExclusiveMaximum(BigDecimal value)
Adds an "exclusiveMaximum" keyword to the schema. The value is specified asBigDecimaltype.This keyword specifies an exclusive upper limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withMinimum
default JsonSchemaBuilder withMinimum(long value)
Adds a "minimum" keyword to the schema. The value is specified as long type.This keyword specifies an inclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withMinimum
default JsonSchemaBuilder withMinimum(double value)
Adds a "minimum" keyword to the schema. The value is specified as double type.This keyword specifies an inclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withMinimum
JsonSchemaBuilder withMinimum(BigDecimal value)
Adds a "minimum" keyword to the schema. The value is specified asBigDecimaltype.This keyword specifies an inclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withExclusiveMinimum
default JsonSchemaBuilder withExclusiveMinimum(long value)
Adds an "exclusiveMinimum" keyword to the schema. The value is specified as long type.This keyword specifies an exclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withExclusiveMinimum
default JsonSchemaBuilder withExclusiveMinimum(double value)
Adds an "exclusiveMinimum" keyword to the schema. The value is specified as double type.This keyword specifies an exclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
-
withExclusiveMinimum
JsonSchemaBuilder withExclusiveMinimum(BigDecimal value)
Adds an "exclusiveMinimum" keyword to the schema. The value is specified asBigDecimaltype.This keyword specifies an exclusive lower limit for a numeric instance.
- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withMaxLength
JsonSchemaBuilder withMaxLength(int value)
Adds a "maxLength" keyword to the schema.This keyword specifies an upper limit of length for a string instance.
- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withMinLength
JsonSchemaBuilder withMinLength(int value)
Adds a "minLength" keyword to the schema.This keyword specifies a lower limit of length for a string instance.
- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withPattern
JsonSchemaBuilder withPattern(String pattern)
Adds a "pattern" keyword to the schema.This keyword specifies the pattern of string instance as a regular expression.
- Parameters:
pattern- the regular expression which will be tested against a string instance.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedpatternisnull.java.util.regex.PatternSyntaxException- if the specifiedpatternis not a valid regular expression.
-
withItems
JsonSchemaBuilder withItems(JsonSchema subschema)
Adds an "items" keyword to the schema. The specified single subschema is used for all array items.- Parameters:
subschema- the subschema as the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withItemsArray
JsonSchemaBuilder withItemsArray(JsonSchema... subschemas)
Adds an "items" keyword to the schema. The value is specified as an array of subschemas.- Parameters:
subschemas- the array of subschemas as the value of the keyword. At least one element is needed.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withItemsArray
JsonSchemaBuilder withItemsArray(List<JsonSchema> subschemas)
Adds an "items" keyword to the schema. The value is specified as an ordered list of subschemas.- Parameters:
subschemas- the list of subschemas as the value of the keyword. At least one element is needed.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withAdditionalItems
JsonSchemaBuilder withAdditionalItems(JsonSchema subschema)
Adds an "additionalItems" keyword to the schema.- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withMaxItems
JsonSchemaBuilder withMaxItems(int value)
Adds a "maxItems" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withMinItems
JsonSchemaBuilder withMinItems(int value)
Adds a "minItems" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withUniqueItems
JsonSchemaBuilder withUniqueItems(boolean unique)
Adds a "uniqueItems" keyword to the schema.This keyword specifies whether elements in the array should be unique or not.
- Parameters:
unique- the value of the keyword.- Returns:
- this builder.
-
withContains
JsonSchemaBuilder withContains(JsonSchema subschema)
Adds a "contains" keyword to the schema.- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withMaxContains
JsonSchemaBuilder withMaxContains(int value)
Adds a "maxContains" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.- Since:
- draft-08
-
withMinContains
JsonSchemaBuilder withMinContains(int value)
Adds a "minContains" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.- Since:
- draft-08
-
withMaxProperties
JsonSchemaBuilder withMaxProperties(int value)
Adds a "maxProperties" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withMinProperties
JsonSchemaBuilder withMinProperties(int value)
Adds a "minProperties" keyword to the schema.- Parameters:
value- the value of the keyword. This must be a non-negative integer.- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the specifiedvalueis negative.
-
withRequired
JsonSchemaBuilder withRequired(String... names)
Adds a "required" keyword to the schema.This keyword specifies the required properties in an object.
- Parameters:
names- the value of the keyword. The names must be unique.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednamesisnull.IllegalArgumentException- if the specifiedvaluesare not unique.
-
withRequired
JsonSchemaBuilder withRequired(Set<String> names)
Adds a "required" keyword to the schema.This keyword specifies the required properties in an object.
- Parameters:
names- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednamesisnull.
-
withProperty
JsonSchemaBuilder withProperty(String name, JsonSchema subschema)
Adds an entry of the "properties" keyword to the schema.- Parameters:
name- the name of the property.subschema- the subschema for the property.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednameorsubschemaisnull.
-
withProperties
JsonSchemaBuilder withProperties(Map<String,JsonSchema> subschemas)
Adds a "properties" keyword to the schema.- Parameters:
subschemas- the object mapping a property name to a subschema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.
-
withPatternProperty
JsonSchemaBuilder withPatternProperty(String pattern, JsonSchema subschema)
Adds an entry of the "patternProperties" keyword to the schema.- Parameters:
pattern- the name pattern the property.subschema- the subschema for the property.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedpatternorsubschemaisnull.java.util.regex.PatternSyntaxException- if the specifiedpatternis not a valid regular expression.
-
withPatternProperties
JsonSchemaBuilder withPatternProperties(Map<String,JsonSchema> subschemas)
Adds a "patternProperties" keyword to the schema.- Parameters:
subschemas- the object mapping a name pattern to a subschema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.java.util.regex.PatternSyntaxException- if any pattern is not a valid regular expression.
-
withAdditionalProperties
JsonSchemaBuilder withAdditionalProperties(JsonSchema subschema)
Adds an "additionalProperties" keyword to the schema.- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withDependency
JsonSchemaBuilder withDependency(String name, JsonSchema subschema)
Adds an entry of the "dependencies" keyword to the schema.- Parameters:
name- the name of the dependency property.subschema- the schema to be evaluated against the entire object.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednameorsubschemaisnull.
-
withDependency
JsonSchemaBuilder withDependency(String name, String... requiredProperties)
Adds an entry of the "dependencies" keyword to the schema.- Parameters:
name- the name of the dependency property.requiredProperties- the required properties in the object.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednameorrequiredPropertiesisnull.IllegalArgumentException- if any element inrequiredPropertiesis not unique.
-
withDependency
JsonSchemaBuilder withDependency(String name, Set<String> requiredProperties)
Adds an entry of the "dependencies" keyword to the schema.- Parameters:
name- the name of the dependency property.requiredProperties- the required properties in the object.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednameorrequiredPropertiesisnull.
-
withDependencies
JsonSchemaBuilder withDependencies(Map<String,?> values)
Adds a "dependencies" keyword to the schema.- Parameters:
values- the object mapping a property name to a value. Each value of the map must be aJsonSchemaor aSet<String>.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvaluesisnull.ClassCastException- if any value of the map is of unexpected type.
-
withPropertyNames
JsonSchemaBuilder withPropertyNames(JsonSchema subschema)
Adds a "propertyNames" keyword to the schema.- Parameters:
subschema- the subschema to be evaluated against all property names in an object.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withIf
JsonSchemaBuilder withIf(JsonSchema subschema)
Adds an "if" keyword to the schema.- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withThen
JsonSchemaBuilder withThen(JsonSchema subschema)
Adds a "then" keyword to the schema.This keyword has no effect when "if" is absent.
- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withElse
JsonSchemaBuilder withElse(JsonSchema subschema)
Adds an "else" keyword to the schema.This keyword has no effect when "if" is absent.
- Parameters:
subschema- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withAllOf
JsonSchemaBuilder withAllOf(JsonSchema... subschemas)
Adds an "allOf" keyword to the schema. The value is specifies as an array.- Parameters:
subschemas- the array of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withAllOf
JsonSchemaBuilder withAllOf(List<JsonSchema> subschemas)
Adds an "allOf" keyword to the schema. The value is specifies as a list.- Parameters:
subschemas- the list of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withAnyOf
JsonSchemaBuilder withAnyOf(JsonSchema... subschemas)
Adds an "anyOf" keyword to the schema. The value is specifies as an array.- Parameters:
subschemas- the array of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withAnyOf
JsonSchemaBuilder withAnyOf(List<JsonSchema> subschemas)
Adds an "anyOf" keyword to the schema. The value is specifies as a list.- Parameters:
subschemas- the list of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withOneOf
JsonSchemaBuilder withOneOf(JsonSchema... subschemas)
Adds a "oneOf" keyword to the schema. The value is specifies as an array.- Parameters:
subschemas- the array of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withOneOf
JsonSchemaBuilder withOneOf(List<JsonSchema> subschemas)
Adds a "oneOf" keyword to the schema. The value is specifies as a list.- Parameters:
subschemas- the list of the subschemas.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemasisnull.IllegalArgumentException- if the specifiedsubschemasis empty.
-
withNot
JsonSchemaBuilder withNot(JsonSchema subschema)
Adds a "not" keyword to the schema.- Parameters:
subschema- the subschema to be negated.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedsubschemaisnull.
-
withFormat
JsonSchemaBuilder withFormat(String attribute)
Adds a "format" keyword to the schema. This method throws an exception if the specifiedattributeis not recognized as a formate attribute.- Parameters:
attribute- the format attribute such as "date-time".- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedattributeisnull.IllegalArgumentException- if the specifiedattributeis not recogznied as a format attribute.- See Also:
withLaxFormat(java.lang.String)
-
withLaxFormat
JsonSchemaBuilder withLaxFormat(String attribute)
Adds a "format" keyword to the schema. This method does not throw an exception even if the specifiedattributeis not recognized as a formate attribute.- Parameters:
attribute- the format attribute such as "date-time".- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedattributeisnull.- See Also:
withFormat(java.lang.String)
-
withContentEncoding
JsonSchemaBuilder withContentEncoding(String value)
Adds a "contentEncoding" keyword to the schema.- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
withContentMediaType
JsonSchemaBuilder withContentMediaType(String value)
Adds a "contentMediaType" keyword to the schema.- Parameters:
value- the value of the keyword.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.IllegalArgumentException- if the specifiedvalueis not a media type.
-
withDefinition
JsonSchemaBuilder withDefinition(String name, JsonSchema schema)
Adds an entry of "definitions" keyword to the schema.- Parameters:
name- the name of the definition to be added.schema- the schema to define.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiednameorschemaisnull.
-
withDefinitions
JsonSchemaBuilder withDefinitions(Map<String,JsonSchema> schemas)
Adds a "definitions" keyword to the schema.- Parameters:
schemas- the object mapping a name to a schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedschemasisnull.
-
withTitle
JsonSchemaBuilder withTitle(String title)
Adds a "title" keyword to the schema.- Parameters:
title- the title of the schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedtitleisnull.
-
withDescription
JsonSchemaBuilder withDescription(String description)
Adds a "description" keyword to the schema.- Parameters:
description- the description of the schema.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifieddescriptionisnull.
-
withDefault
JsonSchemaBuilder withDefault(JsonValue value)
Adds a "default" keyword to the schema.- Parameters:
value- the default value.- Returns:
- this builder.
- Throws:
NullPointerException- if the specifiedvalueisnull.
-
-