public final class JSONSchema extends Object
Type
.$ref
when encountered.Modifier and Type | Method and Description |
---|---|
int |
depth()
Computes the depth of the schema, i.e., the maximal number of nested objects.
|
JSONSchema |
dropAllOfAnyOfOneOfAndNot()
Returns a copy of this schema without the sub-schemas for
allOf ,
anyOf , oneOf , and not . |
JSONSchema |
getAdditionalProperties()
Returns the schema describing the additional properties of this schema.
|
Set<String> |
getAllKeysDefinedInSchema()
Retrieves all the keys present in this schema.
|
JSONSchema |
getAllOf()
Gets a single schema obtained by merging together all the sub-schemas in the
allOf array. |
List<Type> |
getAllowedTypes()
Gets all the types that are allowed in this schema.
|
List<JSONSchema> |
getAnyOf()
Gets a list containing one schema by element in the
anyOf array. |
boolean |
getBoolean(String key) |
boolean |
getBooleanOr(String key,
boolean defaultValue) |
Object |
getConstValue()
Returns the const value defined in this schema.
|
<T> T |
getConstValueIfType(Class<T> type)
Returns the const value defined in this schema, if the value's type matches the provided type.
|
double |
getDouble(String key) |
double |
getDoubleOr(String key,
double defaultValue) |
Set<Object> |
getForbiddenValues()
Gets all the values that are forbidden by this schema.
|
<T> Set<T> |
getForbiddenValuesFilteredByType(Class<T> type)
Gets all the values of the given type that are forbidden by this schema.
|
int |
getInt(String key) |
int |
getIntOr(String key,
int defaultValue) |
List<JSONSchema> |
getItemsArray()
Gets the sub-schemas for the items in an array.
|
Map<String,JSONSchema> |
getNonRequiredProperties()
Gets the pairs key-value that are not required by this schema.
|
List<JSONSchema> |
getNot()
Gets a list of sub-schemas, after propagating the
not inside
each sub-schema. |
Number |
getNumber(String key) |
Number |
getNumberOr(String key,
Number defaultValue) |
List<JSONSchema> |
getOneOf()
Gets a list containing one possible combination of the elements in the
oneOf array, by applying the XOR operation. |
JSONSchema |
getRawNot()
Get the contents of the key
not , without any modifications. |
Map<String,JSONSchema> |
getRequiredProperties()
Gets the pairs key-value that are required by this schema.
|
Set<String> |
getRequiredPropertiesKeys()
Gets the keys that are required in this schema's properties.
|
JSONSchemaStore |
getStore()
Returns the
JSONSchemaStore holding this schema. |
String |
getString(String key) |
String |
getStringOr(String key,
String defaultValue) |
JSONSchema |
getSubSchema(String key)
Gets the sub-schema for the key
key . |
JSONSchema |
getSubSchemaProperties(String key)
Gets the sub-schema for the property
key . |
boolean |
isArray()
Returns true if this schema allows the type ARRAY.
|
boolean |
isBoolean()
Returns true if this schema allows the type BOOLEAN.
|
boolean |
isEnum()
Returns true if this schema allows the type ENUM.
|
boolean |
isInteger()
Returns true if this schema allows the type INTEGER.
|
boolean |
isNull()
Returns true if this schema allows the type NULL.
|
boolean |
isNumber()
Returns true if this schema allows the type NUMBER.
|
boolean |
isObject()
Returns true if this schema allows the type OBJECT.
|
boolean |
isString()
Returns true if this schema allows the type STRING.
|
JSONSchema |
merge(JSONSchema other)
Merge this schema with an other schema.
|
boolean |
needsFurtherUnfolding()
Checks whether there are still some constraints in some sub-schemas that must
be merged with the whole schema.
|
String |
toString() |
public int depth() throws JSONSchemaException
JSONSchemaException
public JSONSchema getAdditionalProperties() throws JSONSchemaException
JSONSchemaException
public Set<String> getAllKeysDefinedInSchema() throws JSONSchemaException
properties
, for
instance), the answer will contain the keys from the sub-schema.JSONSchemaException
public List<Type> getAllowedTypes()
public Set<Object> getForbiddenValues()
"not": {"const": 5}
imposes that 5
is a forbidden value.public <T> Set<T> getForbiddenValuesFilteredByType(Class<T> type)
getForbiddenValues
and only keeping the
values with the correct type.T
- The typetype
- A class instance for Tpublic Object getConstValue()
public <T> T getConstValueIfType(Class<T> type)
T
- The required typetype
- The required classpublic boolean isEnum()
public boolean isObject()
public boolean isArray()
public boolean isInteger()
public boolean isNumber()
public boolean isBoolean()
public boolean isString()
public boolean isNull()
public boolean needsFurtherUnfolding()
not
,
allOf
, anyOf
, or oneOf
, it may happen
that we end up with these keys again. In this case, we have to repeat the
merging process to remove these keys.
Note that the function may return false
even if one of the above
keys is still present, if the constraints inside the sub-schema can not be
simplified by merging. These occurences must be handled explicitly by the
generator or validator.true
if there are constraints in sub-schemas that can be
merged with this schema.public Set<String> getRequiredPropertiesKeys() throws JSONSchemaException
JSONSchemaException
- If this schema does not allow the type OBJECT.public Map<String,JSONSchema> getRequiredProperties() throws JSONSchemaException
JSONSchemaException
- If this schema does not allow the type OBJECT.public Map<String,JSONSchema> getNonRequiredProperties() throws JSONSchemaException
additionalProperties
and
patternProperties
, if they are allowed.JSONSchemaException
- If this schema does not allow the type OBJECT.public JSONSchema dropAllOfAnyOfOneOfAndNot() throws JSONSchemaException
allOf
,
anyOf
, oneOf
, and not
.JSONSchemaException
- If it is not possible to construct a copy of this
schema.public JSONSchema getAllOf() throws JSONSchemaException
allOf
array.
If there is no allOf
key, the true schema is returned.allOf
.JSONSchemaException
public List<JSONSchema> getAnyOf() throws JSONSchemaException
anyOf
array.
If there is no anyOf
key, a singleton list containing the true
schema is returned.allOf
array.JSONSchemaException
public List<JSONSchema> getOneOf() throws JSONSchemaException
oneOf
array, by applying the XOR operation.
If oneOf
contains the elements A, B, C
, then this
function produces three schemas:
{A, "not": B, "not": C}
{"not": A, B, "not": C}
{"not": A, "not": B, C}
oneOf
key, returns a singleton list containing
the true schema.JSONSchemaException
public JSONSchema merge(JSONSchema other) throws JSONSchemaException
other
- The other schemaJSONSchemaException
- If it is not possible to merge the schemas.public JSONSchema getRawNot() throws JSONSchemaException
not
, without any modifications.not
.JSONSchemaException
- If it is not possible to construct the
sub-schema.public List<JSONSchema> getNot() throws JSONSchemaException
not
inside
each sub-schema.
That is, if this schema contains "not": {A, B, C}
, this function
returns a list with three elements. Each element is obtained by applying the
not
inside A, B, and C, respectively.
That is, it transforms a NOT AND
into an OR NOT
.
If there is no not
key, returns a singleton list with the true
schema.JSONSchemaException
public JSONSchema getSubSchemaProperties(String key) throws org.json.JSONException, JSONSchemaException
key
.key
- The key inside the properties.org.json.JSONException
- If the properties
sub-schema does
not contain key
.JSONSchemaException
- If it is not possible to construct the
sub-schema.public JSONSchema getSubSchema(String key) throws org.json.JSONException, JSONSchemaException
key
.key
- The key.org.json.JSONException
- If this schema does not contain key
.JSONSchemaException
- If it is not possible to construct the
sub-schema.public List<JSONSchema> getItemsArray() throws JSONSchemaException
JSONSchemaException
- If it is not possible to construct one of the
sub-schemas.public int getInt(String key)
public int getIntOr(String key, int defaultValue)
public double getDouble(String key)
public double getDoubleOr(String key, double defaultValue)
public boolean getBoolean(String key)
public boolean getBooleanOr(String key, boolean defaultValue)
public JSONSchemaStore getStore()
JSONSchemaStore
holding this schema.Copyright © 2022. All rights reserved.