Class OpenapiContract
java.lang.Object
ch.nexsol.gateway.validation.OpenapiContract
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 ClassesModifier and TypeClassDescriptionstatic interfaceWhat the contract has to say about a request path and method. -
Constructor Summary
ConstructorsConstructorDescriptionOpenapiContract(io.swagger.v3.oas.models.OpenAPI document) Creates a contract from a parsed document. -
Method Summary
Modifier and TypeMethodDescriptioncom.networknt.schema.JsonSchemacompiledSchema(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.Resolves the contract operation that should handle the given request.
-
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$refresolved
-
-
Method Details
-
resolve
Resolves the contract operation that should handle the given request.- Parameters:
path- the request path, relative to the paths the contract declaresmethod- 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 roleschema- the contract schema- Returns:
- the compiled schema
-