[BUG] ExampleGenerator.generateFromResponseSchema treats the keys of an inline object `example` (java.util.Map) as media types
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- backend-api-design
Research direction
Start in ExampleGenerator.generateFromResponseSchema(Schema, Set) and trace how a non-null inline schema example reaches the generate overloads. Check the existing tests for response schema examples and add coverage for a Java Map example with application/json as the produced media type. Done means the map is emitted as one example under that media type, rather than treating its keys as media types.
Written by the indexing model from the issue text.
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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?
Description
When generateFromResponseSchema(statusCode, schema, produces) gets an inline (non-$ref, non-array) schema whose example is a java.util.Map, the "primitive type" branch casts the example to Map<String, Object> and passes it as the examples argument of generate(Map, List, Schema). That argument means {mediaType -> example}, so every key of the example becomes a contentType and every value becomes a separate example:
Schema<Object> response = new ObjectSchema()
.addProperty("id", new IntegerSchema())
.addProperty("name", new StringSchema());
response.setExample(Map.of("id", 1, "name", "Rex"));
new ExampleGenerator(Map.of(), new OpenAPI())
.generateFromResponseSchema("200", response, Set.of("application/json"));
// actual: [{contentType=name, example="Rex", statusCode=200}, {contentType=id, example=1, statusCode=200}]
// expected: [{contentType=application/json, example={"id":1,"name":"Rex"}, statusCode=200}]
When the spec is read from a file, swagger-parser gives the example as a Jackson ObjectNode, not a Map, so the CLI does not hit this path. It affects programmatic use, such as custom generators or tools that build or transform the OpenAPI model with plain Java maps.
openapi-generator version
7.25.0 (also current master).
Suggest a fix
In generateFromResponseSchema(Schema, Set), handle any non-null example (including Map) through generate(Object, List), and use the generate(Map, ...) overloads only for the media-type map.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 141
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from OpenAPITools/openapi-generator
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenAPITools/openapi-generator#25237 ·
Maintainers usually reply within 1 day
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)Possibly taken @mohitduhan19 claimed this today. OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenAPITools/openapi-generator#25233 ·
Maintainers usually reply within 1 day
-
[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabledPossibly taken @mohitduhan19 claimed this today. OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenAPITools/openapi-generator#25232 ·
Maintainers usually reply within 1 day
-
[BUG][KOTLIN] multiplatform/jvm-ktor: `DELETE` without `requestBody` sends `"Content-Type: application/json"` with an empty bodyPossibly taken @mohitduhan19 claimed this today. OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenAPITools/openapi-generator#25223 ·
Maintainers usually reply within 1 day
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OpenAPITools/openapi-generator#25218 ·
Maintainers usually reply within 1 day
All issues in OpenAPITools/openapi-generator
Similar issues
-
:ml/Transform >bug Team:ML
Difficulty 2/5 Half a day Newbie friendliness 64/100
elastic/elasticsearch#161960 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Tiviacz1337/Travelers-Backpack#1629 ·
-
bug: Authentication and App Check listeners leak the Activity and WebView on AndroidPossibly taken @harbinzhang claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
capawesome-team/capacitor-firebase#1050 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
capawesome-team/capacitor-plugins#1134 ·
Maintainers usually reply within 1 day