Provide mechanisms for users to register own types and format
See original GitHub issueAs discussed in the latest hangout (and related to https://github.com/smallrye/smallrye-open-api/issues/147)
It would be useful to have a mechanism that allows users to:
- Provide their own mappings for types (whether their own, or overriding defaults) to particular primitive type and formats – see Mike Edgar’s comments here https://github.com/smallrye/smallrye-open-api/issues/147#issuecomment-507232015
For example, this could be as simple as:
mp.openapi.extensions.type-format.FQCN=SchemaType,DataFormat
So you could map your custom date type to the correct SchemaType and DataFormat.
-
As suggested by @EricWittmann in the the meeting was that we may also want to consider a more advanced mechanism that allows a schema to be mapped to a particular object (i.e. for cases where it’s not simply about primitives). Eric mentioned the recent SmallRye Custom Schema Registry (https://github.com/smallrye/smallrye-open-api/pull/126/files) as a possible model.
-
I suggested that (in addition to config-driven), a programmatic interface might be beneficial, in allowing runtimes to inject certain mapping information they already know about (e.g. for some type that a framework commonly provides).
There are some parallels here with the way that Jackson works – they have a large number of converters OOTB that take (e.g. Map, Simple Java Bean, List, Date) and convert it into something sensible in JSON. However, if you provide your own complex data structure you need to provide your own converter and/or mapping.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (14 by maintainers)
Top GitHub Comments
The changes for this are complete, with one idea we had not discussed yet. If a user provides a
"name"
property in the config JSON, the implementations should place the schema undercomponents.schemas
using the value of"name"
property as the schema’s key. This would provide a portable way for users to use a$ref
to a schema defined in the config file.If there is no negative feedback on that point, I’ll open the PR.
If everyone is in agreement with the latest part of the discussion, I can work on updating the spec document and adding a test.