swagger-api / swagger-api/swagger-core
Insufficient OpenAPI specification content produced for polymorphic data
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the OpenAPI generation path for polymorphic response types and the test case added for issue #2340. Compare its generated OAS fragment with the OpenAPI discriminator requirements; done means the output includes the discriminator mapping and the subtype references through oneOf or anyOf.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100