OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] [openapi-yaml] [spring] wrong generated example text

Open
#19,063 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

direct usage of allOf destroyes the example of a property with type object without further properties.

expected output (with v7.4.0)

yaml

            example:
              someMeaningfulNumber: 25009779801

java

String exampleString = "{ \"data\" : { \"someMeaningfulNumber\" : 25009779801 }, \"someProperty\" : \"someProperty\" }";

failing output (>7.4.0)

yaml

      example:
        data: "{\"someMeaningfulNumber\":25009779801}"

java

String exampleString = "{ \"data\" : \"{\\"someMeaningfulNumber\\":25009779801}\", \"someProperty\" : \"someProperty\" }";

the generated yaml can't be used for further generation. the generated java code doesn't compile.

openapi-generator version

7.4.0 -> OK
7.5.0 -> fail
7.6.0 -> fail
7.7.0 -> fail

OpenAPI declaration file content or url

https://github.com/kingofdisasterr/openapi-generator-example/blob/main/src/main/resources/yaml/someinterface.yaml

full project:
https://github.com/kingofdisasterr/openapi-generator-example

Generation Details

mvn clean verifyof https://github.com/kingofdisasterr/openapi-generator-example/blob/main/pom.xml

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 linked someinterface.yaml and run mvn clean verify in the reproduction project, comparing generation with OpenAPI Generator 7.4.0 and later versions. Trace the generated YAML and Java example output to identify where the object example becomes a string. Done means the YAML preserves the object example and the generated Java example compiles as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.