OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java/Spring] additionalProperties to true breaks compilation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- 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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
v5.0.0-beta2 and v5.0.0-beta3 do not generate correct Java putPropertiesItem method for Map fields
openapi-generator version
v5.0.0-beta2, v5.0.0-beta3 and latest
Works ok in v5.0.0-beta
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Test
version: '1.0.0'
paths:
/test:
get:
summary: Test
description: Example
responses:
200:
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/test'
components:
schemas:
test:
type: object
required:
- field_A
- field_B
properties:
field_A:
type: string
enum:
- Feature
field_B:
type: integer
properties:
type: object
properties:
field_C:
type: integer
additionalProperties: true
Generation Details
cat out/java/src/main/java/org/openapitools/model/Test.java
Expected
public Test putPropertiesItem(String key, Object propertiesItem) {
if (this.properties == null) {
this.properties = new HashMap<>();
}
this.properties.put(key, propertiesItem);
return this;
}
vs
public Test putPropertiesItem(String key, Object propertiesItem) {
if (this.properties == null) {
this.properties = ;
}
this.properties.put(key, propertiesItem);
return this;
}
Steps to reproduce
docker run --rm \
-v $PWD:/local openapitools/openapi-generator-cli:v5.0.0-beta3 generate \
-i /local/test.yaml \
-g spring \
-o /local/out/java
Related issues/PRs
Suggest a fix
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 the supplied OpenAPI YAML and the documented Docker command using the spring generator, then inspect the generated out/java/src/main/java/org/openapitools/model/Test.java. Trace how additionalProperties: true produces putPropertiesItem and verify the generated project compiles with the expected HashMap initialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100