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

[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`

Open Beginner friendly
#25,237 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, openapi
Domain
api

Research direction

Find resolvePropertyToExample and resolveModelToExample in the Java code that implements ExampleGenerator; the issue does not name their file or a test. Start by reproducing with the provided OpenAPI schema and checking how unresolved $ref values are handled. Done means object schemas without properties produce an empty JSON object in both nested and top-level examples, rather than a string or null.

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

resolvePropertyToExample returns the Java string literal "{}" for an object schema without properties and for a $ref that cannot be resolved. Json.pretty then serializes it as a JSON string ("metadata" : "{}") instead of an empty object ("metadata" : { }), so the example has the wrong type (JSON Schema Validation wright-00, 5.21).

The same happens one level up. For a top-level model type: object without properties, resolveModelToExample falls through to return null, and generate(null, ["application/json"], "Anything") returns the example null. Through the CLI this model gets unaliased first, so the operation simply has no example; only programmatic callers see null.

openapi-generator version

7.25.0 (also current master).

OpenAPI declaration file content or url
components:
  schemas:
    Reading:
      type: object
      properties:
        metadata:
          type: object
Steps to reproduce

generate -g html → "Example data" shows "metadata" : "{}". Expected: "metadata" : { }.

Suggest a fix

Return new LinkedHashMap<>() (an empty map) instead of the string "{}" in both branches of resolvePropertyToExample, and also for object schemas without properties in resolveModelToExample.

Dominant language
Java
Stars
26.8k
Forks
7.7k
Avg merge
1d 11h
Merged PRs (30d)
139

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.