Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG] ExampleGenerator.generateFromResponseSchema treats the keys of an inline object `example` (java.util.Map) as media types

Open Beginner friendly
#25,236 0 comments 0 reactions 0 assignees View on GitHub

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

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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.