[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
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
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#25236 ·
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 A pull request linked to this issue is open or already merged. 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 A pull request linked to this issue is open or already merged. 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 A pull request linked to this issue is open or already merged. 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
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
wildfly/wildfly-launcher#99 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
traccar/traccar#6076 · 2 comments ·
Maintainers usually reply within 1 day
-
Flight SQL JDBC parses boolean properties case-sensitively, silently disabling TLS for useEncryption=TRUEPossibly taken @Arawoof06 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
apache/arrow-java#1357 ·
Maintainers usually reply within 1 day
-
[Bug] Demo alert imports accept empty and oversized rule documentsPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
apache/rocketmq-dashboard#6610 ·
Maintainers usually reply within 3 days