Package io.vertx.json.schema
Interface SchemaRepository
-
public interface SchemaRepository
A repository is a holder of dereferenced schemas, it can be used to create validator instances for a specific schema.This is to be used when multiple schema objects compose the global schema to be used for validation.
- Author:
- Paulo Lopes
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static SchemaRepository
create(JsonSchemaOptions options)
Create a repository with some initial configuration.static SchemaRepository
create(JsonSchemaOptions options, JsonFormatValidator jsonFormatValidator)
Create a repository with some initial configuration.SchemaRepository
dereference(JsonSchema schema)
Dereferences a schema to the repository.SchemaRepository
dereference(String uri, JsonSchema schema)
Dereferences a schema to the repository.JsonSchema
find(String pointer)
Look up a schema using a JSON pointer notationSchemaRepository
preloadMetaSchema(FileSystem fs)
Preloads the repository with the meta schemas for the related @linkDraft
version.SchemaRepository
preloadMetaSchema(FileSystem fs, Draft draft)
Preloads the repository with the meta schemas for the related draft version.JsonObject
resolve(JsonObject schema)
Resolve all$ref
in the givenJsonObject
.Validator
validator(JsonSchema schema)
A new validator instance using this repository options.default Validator
validator(JsonSchema schema, JsonSchemaOptions options)
A new validator instance overriding this repository options.Validator
validator(JsonSchema schema, JsonSchemaOptions options, boolean dereference)
A new validator instance overriding this repository options.Validator
validator(String ref)
A new validator instance using this repository options.Validator
validator(String ref, JsonSchemaOptions options)
A new validator instance overriding this repository options.
-
-
-
Method Detail
-
create
static SchemaRepository create(JsonSchemaOptions options)
Create a repository with some initial configuration.- Parameters:
options
- the initial configuration- Returns:
- a repository
-
create
static SchemaRepository create(JsonSchemaOptions options, JsonFormatValidator jsonFormatValidator)
Create a repository with some initial configuration.- Parameters:
options
- the initial configuration- Returns:
- a repository
-
dereference
SchemaRepository dereference(JsonSchema schema) throws SchemaException
Dereferences a schema to the repository.- Parameters:
schema
- a new schema to list- Returns:
- a repository
- Throws:
SchemaException
- when a schema is already present for the same id
-
dereference
SchemaRepository dereference(String uri, JsonSchema schema) throws SchemaException
Dereferences a schema to the repository.- Parameters:
uri
- the source of the schema used for de-referencing, optionally relative toJsonSchemaOptions.getBaseUri()
.schema
- a new schema to list- Returns:
- a repository
- Throws:
SchemaException
- when a schema is already present for the same id
-
preloadMetaSchema
SchemaRepository preloadMetaSchema(FileSystem fs)
Preloads the repository with the meta schemas for the related @linkDraft
version. The related draft version is determined from theJsonSchemaOptions
, in case that no draft is set in the options anIllegalStateException
is thrown.- Parameters:
fs
- The Vert.x file system to load the related schema meta files from classpath- Returns:
- a repository
-
preloadMetaSchema
SchemaRepository preloadMetaSchema(FileSystem fs, Draft draft)
Preloads the repository with the meta schemas for the related draft version.- Parameters:
fs
- The Vert.x file system to load the related schema meta files from classpathdraft
- The draft version of the meta files to load- Returns:
- a repository
-
validator
Validator validator(JsonSchema schema)
A new validator instance using this repository options.- Parameters:
schema
- the start validation schema- Returns:
- the validator
-
validator
Validator validator(String ref)
A new validator instance using this repository options. This is the preferred way to create a validator as it avoids reparsing schemas and reuses the cache in the repository.- Parameters:
ref
- the start validation reference in JSON pointer format- Returns:
- the validator
-
validator
Validator validator(String ref, JsonSchemaOptions options)
A new validator instance overriding this repository options. This is the preferred way to create a validator as it avoids reparsing schemas and reuses the cache in the repository.- Parameters:
ref
- the start validation reference in JSON pointer formatoptions
- the options to be using on the validator instance- Returns:
- the validator
-
validator
default Validator validator(JsonSchema schema, JsonSchemaOptions options)
A new validator instance overriding this repository options. The given schema will not be referenced to the repository.- Parameters:
schema
- the start validation schemaoptions
- the options to be using on the validator instance- Returns:
- the validator
-
validator
Validator validator(JsonSchema schema, JsonSchemaOptions options, boolean dereference)
A new validator instance overriding this repository options.- Parameters:
schema
- the start validation schemaoptions
- the options to be using on the validator instancedereference
- if true the schema will be dereferenced before validation- Returns:
- the validator
-
resolve
JsonObject resolve(JsonObject schema)
Resolve all$ref
in the givenJsonObject
. The resolution algrithm is not aware of other specifications. When resolving OpenAPI documents (which only allow$ref
at specific locations) you should validate if the document is valid before performing a resolution. It is important to note that any sibling elements of a$ref
is ignored. This is because$ref
works by replacing itself and everything on its level with the definition it is pointing at.- Parameters:
schema
- the JSON object to resolve.- Returns:
- a new JSON object with all the
$ref
replaced by actual object references. - Throws:
IllegalArgumentException
- when the input JSON is not valid.UnsupportedOperationException
- reducing the JSON pointer to a value is undefined.
-
find
JsonSchema find(String pointer)
Look up a schema using a JSON pointer notation- Parameters:
pointer
- the JSON pointer- Returns:
- the schema
-
-