OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Spring] OneOf discriminator seems to ignore type format which causes type mismatch

Open
#18,693 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

OneOf interfaces that should use string+uri as discriminator only use String, which causes a type mismatch because the discriminator is being generated as URI in the classes.

openapi-generator version

7.5.0

OpenAPI declaration file content or url

https://gist.github.com/Kaemmelot/ad720f03f4f536bb0f54ec281e02479d

Generation Details

java -jar openapi-generator-cli-7.5.0.jar generate -i api.yml -g spring

Steps to reproduce

see Gist above, PetResponse has a wrong type for getPetType()

Related issues/PRs

did not find any

Suggest a fix

It could be that the format of the type is not taken into account when generating such a oneOf interface.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the api.yml from the linked Gist and run the documented openapi-generator-cli 7.5.0 Spring generation command. Inspect the generated PetResponse and its getPetType() method, comparing the OneOf discriminator type with the string+uri types in the generated classes. Done means the discriminator uses a compatible type and the generated code no longer has the reported type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.