OpenAPITools / OpenAPITools/openapi-generator
[Go][Experimental] OneOf Implementation does not work without explicit mapping defined in spec
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
As per the discriminator section in the OAS spec (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#discriminatorObject), the mapping part should be optional and required only when an implicit mapping is not possible.
I do not see implicit mapping derivation working with go-experimental generator today. The Unmarshal code does not generate any type specific unmarshal code for each of the OneOf types.
This should be enough
┆ ntp.Policy.Response:
┆ ┆ description: test
┆ ┆ oneOf:
┆ ┆ ┆ - $ref: '#/components/schemas/mo.DocumentCount'
┆ ┆ ┆ - $ref: '#/components/schemas/ntp.Policy.List'
┆ ┆ discriminator:
┆ ┆ ┆ propertyName: ObjectType
But current generator seem to require this,
┆ ntp.Policy.Response:
┆ ┆ description: test
┆ ┆ oneOf:
┆ ┆ ┆ - $ref: '#/components/schemas/mo.DocumentCount'
┆ ┆ ┆ - $ref: '#/components/schemas/ntp.Policy.List'
┆ ┆ discriminator:
mapping:
┆ ┆ ┆ ┆ mo.DocumentCount: '#/components/schemas/mo.DocumentCount'
┆ ┆ ┆ ┆ ntp.Policy.List: '#/components/schemas/ntp.Policy.List'
┆ ┆ ┆ propertyName: ObjectType
openapi-generator version
latest master
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
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 with the go-experimental generator's OneOf and Unmarshal generation for the provided OpenAPI schema, comparing output with and without an explicit discriminator mapping. Done means generated Go code derives implicit mappings and emits type-specific unmarshal behavior without requiring the mapping section.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100