Skip to content

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

Open

Description

@knusth

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.

Activity

  1. rajeshvasa commented on Nov 15, 2026

    @rajeshvasa
    Contributor

    Looks like this was resolved by #25253 (merged Oct 19), which returns an empty object for both the nested and top-level cases and keeps the unresolved-$ref fallback intentionally. I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions