Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient OpenAPI specification content produced for polymorphic data #4460

Open
demonti opened this issue Aug 3, 2023 · 1 comment
Open

Comments

@demonti
Copy link

demonti commented Aug 3, 2023

I am investigating the use of subclasses in responses of REST operations, but don't get it to work as I expected. I came across the issue #2340, which has been closed. The fix included a test case with the expected OAS fragment. However, I regard the expected/generated fragment as insufficient.

The OpenAPI specification (both 3.0.3 and 3.1) specifies the "Discriminator Object" in section 4.7.25 (3.0.3) / 4.8.25 (3.1). This contains a field named "mapping", containing a map from the concrete type name to the concrete JSON Schema data type. While this field is marked as "optional" in the document, it is actually essential for any code generator that wants to create code to deserialize JSON into a language's object representation.

Playing around with the "OpenAPI generator" using a modified OAS file, it turns out that even the addition of the "mapping" entry is not sufficient, at least for the TypeScript generator I am working with. It also needs the JSON Schema "oneOf"/"anyOf" construct with the references to the actual subtypes to be present as well, as depicted in the OpenAPI specification 3.0.3/3.1.

So I suggest to add both the "mapping" and "oneOf"/"anyOf" definition when generating an OAS file.

@jochenberger
Copy link

See also #4330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants