OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][jaxrs-spec] When using discriminator, enum properties of children are defined in parent instead of child class

Open
#19,009 0 comments 0 reactions 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

When I define a schema with discriminator and a child has an enum property, the enum definition and the property is generated into the parent and therefore available for all other children. This also results in a compile error when generating the equals and hashCode methods.

This issue is currently blocking any updates of this generator for me.

openapi-generator version

I tried the latest master (7.7.0-20240520.095624). It worked with 7.2.0 and is broken since 7.3.0

OpenAPI declaration file content or url

https://gist.github.com/Gerschtli/197faf5d172bcaf63d08cedaa364107f

Generation Details
java -jar openapi-generator.jar generate -g jaxrs-spec -i spec.yaml
Steps to reproduce

Use provided spec.yaml and generate java code with the command from above.

Related issues/PRs

I did not find any related Issues/PRs.

Suggest a fix

I don't have any workaround. As this is currently blocking me, any workaround would be appreciated!

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 by running java -jar openapi-generator.jar generate -g jaxrs-spec -i spec.yaml with the specification from the linked gist and compare the generated parent and child classes. Trace Java jaxrs-spec generation around the regression introduced after version 7.2.0; done means the enum property is defined only on its child and the generated equals and hashCode code compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.