Class OpenApiSpec

java.lang.Object
io.wcm.siteapi.openapi.validator.OpenApiSpec

public final class OpenApiSpec extends Object
Reads and validates an OAS3 YAML specification. Gives access to OpenApiSchemaValidator instances for each path/suffix defined in the specification.
  • Constructor Details

    • OpenApiSpec

      public OpenApiSpec(@NotNull @NotNull String path, @NotNull @NotNull String version)
      Create instance with given spec files.
      Parameters:
      path - Resource Path to OAS3 spec
      version - Spec version or empty string
      Throws:
      SpecInvalidException - If reading OAS3 spec fails.
    • OpenApiSpec

      public OpenApiSpec(@NotNull @NotNull URL url, @NotNull @NotNull String version)
      Create instance with given spec files.
      Parameters:
      url - URL pointing to OAS3 spec
      version - Spec version or empty string
      Throws:
      SpecInvalidException - If reading OAS3 spec fails.
  • Method Details

    • getURL

      @NotNull public @NotNull URL getURL()
      Returns:
      Specification URL.
    • getVersion

      @NotNull public @NotNull String getVersion()
      Returns:
      Spec version (derived from file name) or empty string.
    • getSchemaValidator

      @NotNull public @NotNull OpenApiSchemaValidator getSchemaValidator(@NotNull @NotNull String suffix)
      Get Schema for default response of operation mapped to given suffix.

      It looks for a path definition ending with /{suffix}.json in the spec and returns the JSON schema defined in the YAML for HTTP 200 GET response with application/json content type.

      See site-api.yaml as minimal example for a valid specification.

      Parameters:
      suffix - Suffix ID
      Returns:
      Schema JSON node
    • toString

      public String toString()
      Overrides:
      toString in class Object