Class SchemaValidator
java.lang.Object
com.atlassian.oai.validator.schema.SchemaValidator
Validate a value against the schema defined in an OpenAPI / Swagger specification.
Supports validation of properties and request/response bodies, and supports schema references.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSchemaValidator(io.swagger.v3.oas.models.OpenAPI api, MessageResolver messages) Build a new validator for the given API specification.SchemaValidator(io.swagger.v3.oas.models.OpenAPI api, MessageResolver messages, Supplier<com.github.fge.jsonschema.main.JsonSchemaFactory> schemaFactorySupplier) Build a new validator for the given API specification.SchemaValidator(io.swagger.v3.oas.models.OpenAPI api, MessageResolver messages, Supplier<com.github.fge.jsonschema.main.JsonSchemaFactory> schemaFactorySupplier, ValidationConfiguration validationConfiguration) Build a new validator for the given API specification. -
Method Summary
Modifier and TypeMethodDescriptionvalidate(SchemaValidator.JsonNodeSupplier supplier, io.swagger.v3.oas.models.media.Schema schema, String keyPrefix) Validate the given value against the given property schema.Validate the given value against the given property schema.
-
Field Details
-
ADDITIONAL_PROPERTIES_KEY
- See Also:
-
INVALID_JSON_KEY
- See Also:
-
UNKNOWN_ERROR_KEY
- See Also:
-
-
Constructor Details
-
SchemaValidator
Build a new validator for the given API specification.- Parameters:
api- The API to build the validator for.messages- The message resolver to use.
-
SchemaValidator
public SchemaValidator(io.swagger.v3.oas.models.OpenAPI api, @Nonnull MessageResolver messages, @Nonnull Supplier<com.github.fge.jsonschema.main.JsonSchemaFactory> schemaFactorySupplier) Build a new validator for the given API specification.- Parameters:
api- The API to build the validator for.messages- The message resolver to use.schemaFactorySupplier- A supplier function to get JsonSchemaFactory.
-
SchemaValidator
public SchemaValidator(io.swagger.v3.oas.models.OpenAPI api, @Nonnull MessageResolver messages, @Nonnull Supplier<com.github.fge.jsonschema.main.JsonSchemaFactory> schemaFactorySupplier, @Nonnull ValidationConfiguration validationConfiguration) Build a new validator for the given API specification.- Parameters:
api- The API to build the validator for.messages- The message resolver to use.schemaFactorySupplier- A supplier function to get JsonSchemaFactory.
-
-
Method Details
-
validate
@Nonnull public ValidationReport validate(@Nonnull String value, @Nullable io.swagger.v3.oas.models.media.Schema schema, @Nullable String keyPrefix) Validate the given value against the given property schema. If the schema is null then any json is valid.- Parameters:
value- The value to validateschema- The schema to validate the value againstkeyPrefix- A prefix to apply to validation messages emitted by the validator- Returns:
- A validation report containing accumulated validation errors
-
validate
@Nonnull public ValidationReport validate(@Nonnull SchemaValidator.JsonNodeSupplier supplier, @Nullable io.swagger.v3.oas.models.media.Schema schema, @Nullable String keyPrefix) Validate the given value against the given property schema. If the schema is null then any json is valid.- Parameters:
supplier- Supplies the JsonNode to validateschema- The schema to validate the value againstkeyPrefix- A prefix to apply to validation messages emitted by the validator- Returns:
- A validation report containing accumulated validation errors
-