[FEATURE]: allOf
instead of oneOf
where applicable
#103
Labels
feature request
This issue requests a feature that doesn't exist (yet)
mapping
This issue or it's solution is related to how information is mapped
PR ready
This issue is approved and ready to be worked on.
Milestone
(copy-paste from #102)
The OpenAPI spec currently contains
oneOf
lists for many schema object fields.In most cases, these fields are mandatory. See for example
PlanetInfo.position
:Now, from a OpenAPI perspective, this is perfectly fine.
The problem I have is the following: I currently use a client code generator in my project which reads through your OpenAPI spec and produces client code for the requests in the spec.
It also produces model structs for each response schema (analogue to your server-side models).
This is where the problem with
oneOf
occurs: all code generators I tested thus far handleoneOf
as an ambiguous type for which the actual type is unknown at runtime. This results in the generator producing intermediate models with multiple types and thus requiring additional client-side steps before the actual model instance is available (resulting in a lot of boilerplate code).Sample client code (Go)
This method receives the immediate (generated) API response struct, but needs to perform additional processing in
AsPosition
to get the actual (usable) type.While I can see the usecase of this for actual ambigous types such as your recently-added localized strings, the example above and almost all other occurences of
oneOf
are different: they occur in places where only one model is possible (i.e. theoneOf
field only has one item).This is where my request comes in: is it possible to switch to
allOf
for these cases? Semantically, this shouldn't make a difference for API specification.It does make a difference for client-side processing though, especially when talking about generated code.
I am aware that the OpenAPI specs are automatically generated from your C# source code, but perhaps there is a way of annotating such fields so that
allOf
instead ofoneOf
is generated?Thanks for reading this far, I hope this wall of text was half understandable.
And just to be clear: it works the way it currently is, it just produces a lot of boilerplate code on my end, so I understand if this problem is too niche and thus not worth the effort.
Please do let me know in that case and I'll happily settle with the current implementation.
The text was updated successfully, but these errors were encountered: