OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Generator fails to create a working client with Springs HttpStatusCode involved

Open
#22,443 5 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?
  • [❌: I couldn't build the latest Snapshot due to proxy and corporate restrictions] Have you tested with the latest master to confirm the issue still exists?
  • [✅] Have you searched for related issues/PRs?
  • [expected: should not result in compile errors] What's the actual output vs expected output?
  • [❌] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using the attached files will result in a non compiling generated client, as seen in the description of Steps to reproduce. This is the minimal example I could create. The actual use-case we have is, to use the attached ApiError class in a ControllerAdvice to react to errors of our services.

openapi-generator version

7.17.0

OpenAPI declaration file content or url

https://gist.github.com/coinzz/24597c69a8877d95e4f10fd681f28ee3

Generation Details
  • Apache Maven 3.9.9
  • openjdk 17.0.12 2024-07-16 LTS
  • also with: openjdk 21.0.4 2024-07-16 LTS
  • the rest is configured in the pom.xml
Steps to reproduce
  1. Put the api-docs.json on the same level as the pom.xml
  2. run mvn generate-sources
  3. This will be succesful, but navigate to generated-sources\client\src\main\java\de\test\client\model\HttpStatus.java
  4. See the Error: Image
Related issues/PRs

I couldn't find a direct related issue.

Suggest a fix

It seems that sealed classes or inheritance break the generation, but I am not sure if that is the concrete problem.

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 attached api-docs.json and pom.xml, then run mvn generate-sources and inspect generated-sources/client/src/main/java/de/test/client/model/HttpStatus.java. Trace the Java client generation path handling the Spring HttpStatusCode-related model and inheritance. Done means the generated client compiles without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, 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.