Class OpenapiContract

java.lang.Object
ch.nexsol.gateway.validation.OpenapiContract

public class OpenapiContract extends Object
A parsed OpenAPI document, ready to validate an exchange against.

Everything that can be computed once is: the path templates are compiled to regular expressions at construction, and the JSON schema of an operation is compiled the first time it is needed and then kept. Validating a message therefore costs no parsing and no IO, which is what makes it safe to do on the event loop.

This class deliberately speaks Jackson 2 rather than the Jackson 3 the rest of the project uses: both swagger-core-jakarta and json-schema-validator expose their models through it, so converting would buy nothing.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    What the contract has to say about a request path and method.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OpenapiContract(io.swagger.v3.oas.models.OpenAPI document)
    Creates a contract from a parsed document.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.networknt.schema.JsonSchema
    compiledSchema(String cacheKey, io.swagger.v3.oas.models.media.Schema<?> schema)
    Returns the compiled JSON schema of the given contract schema, compiling it on first use.
    resolve(String path, org.springframework.http.HttpMethod method)
    Resolves the contract operation that should handle the given request.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OpenapiContract

      public OpenapiContract(io.swagger.v3.oas.models.OpenAPI document)
      Creates a contract from a parsed document.
      Parameters:
      document - the parsed OpenAPI document, with its $ref resolved
  • Method Details

    • resolve

      public OpenapiContract.Resolution resolve(String path, org.springframework.http.HttpMethod method)
      Resolves the contract operation that should handle the given request.
      Parameters:
      path - the request path, relative to the paths the contract declares
      method - the request method
      Returns:
      what the contract has to say about that path and method
    • compiledSchema

      public com.networknt.schema.JsonSchema compiledSchema(String cacheKey, io.swagger.v3.oas.models.media.Schema<?> schema)
      Returns the compiled JSON schema of the given contract schema, compiling it on first use.
      Parameters:
      cacheKey - the key the compiled schema is kept under, unique per operation and role
      schema - the contract schema
      Returns:
      the compiled schema