OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java] Generated code doesn't compile if the default value of an object is an empty object `{}`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating a client package with the java generator using the library=native, if an object has a default value of {}, the generated code doesn't compile.
This might also be true for other library values but I didn't check.
openapi-generator version
7.7.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Basic API
description: A simple API that returns an object with a name and a value.
version: 1.0.0
paths:
/item:
get:
summary: Get an item
description: Returns an object with a name and a value.
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
name:
type: string
value:
$ref: '#/components/schemas/Value'
components:
schemas:
Value:
type: object
default: {}
properties:
optionalProperty:
type: string
description: This is an optional property.
Generation Details
openapi-generator-cli generate -i specs.yaml -c config.json -g java -o client
config.json:
{ "library": "native" }
Steps to reproduce
Run the command with the given specs.yaml and config.json
Then try to compile the code with cd client && mvn package
Compilation fails with the following error message:
client/src/main/java/org/openapitools/client/model/ItemGet200Response.java:[46,25] illegal initializer for org.openapitools.client.model.Value
The code contains:
...
private Value value = {};
...
Contributor 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.
Research direction
Reproduce the issue with specs.yaml and config.json, using the Java generator with library=native. Inspect the generated ItemGet200Response.java around the Value initializer, then run cd client && mvn package to confirm the failure. Done means the generated client compiles successfully when the schema default is an empty object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100