Allow Support of Custom Media Types #116
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
In the current implementation, it is impossible to use OpenAPI schemas that have media types which are unsupported by the library. In our concrete use case, we have multiple SSE endpoints (media type
text/event-stream) that are not supposed to be validated, butvertx-openapistill refuses to parse the contract, as the media type is none of the predefined supported media types.In this PR, I extend the
OpenAPIContractBuilderto allow users to specify additional supported media types, as long as they provide a mapping of those media types to JSON (for schema validation) or specify that the media type should be treated as an opaque string and remain unchecked.The main user-facing change are two new methods in
OpenAPIContractBuilderand a new interface for constructing customContentAnalysers:OpenAPIContractBuilder.registerSupportedMediaTyperegisters a media type together with aContentAnalyserFactorythat provides a JSON mapping of that media typeOpenAPIContractBuilder.registerUncheckedMediaTyperegisters a media type as an opaque unchecked stringContentAnalyserFactorycreates content analysers. Users can create their own implementations ofContentAnalyserand a matching factory in order to support custom media types.Internally, a map of additional supported media types is passed down through the OpenAPIContractImpl hierarchy at construction time. The
MediaTypeImplclass stores a reference to the matching customContentAnalyserFactory, if any.All changes are tested and documented.