Class SchemaValidator

java.lang.Object
com.atlassian.oai.validator.schema.SchemaValidator

public class SchemaValidator extends Object
Validate a value against the schema defined in an OpenAPI / Swagger specification.

Supports validation of properties and request/response bodies, and supports schema references.

  • Field Details

  • Constructor Details

    • SchemaValidator

      public SchemaValidator(io.swagger.v3.oas.models.OpenAPI api, @Nonnull MessageResolver messages)
      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 validate
      schema - The schema to validate the value against
      keyPrefix - 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 validate
      schema - The schema to validate the value against
      keyPrefix - A prefix to apply to validation messages emitted by the validator
      Returns:
      A validation report containing accumulated validation errors