OpenAPITools / OpenAPITools/openapi-generator
[JAVA] Object type with 'additionalProperties' not annotated/generated properly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
We have the following type/object, namely it is a dictionary/map, but it has one custom property, namely 'extras'.
links:
description: Links object
type: object
additionalProperties:
$ref: "#/components/schemas/hrefType"
properties:
extras:
$ref: "#/components/schemas/hrefType"
components:
schemas:
hrefType:
description: Link to a resource
type: string
example: "/test/1234"
The following code will be generated. If we set the property extras via the builder method, it will not be part of the serialized JSON object.
public class Links extends HashMap<String, String> {
@JsonProperty("extras")
private String extras;
public Links extras(String extras) {
this.extras = extras;
return this;
}
// ...
}
openapi-generator version
3.3.1
OpenAPI declaration file content or url
See description.
Command line used for generation
/
Steps to reproduce
/
Related issues/PRs
OpenAPI Generator: https://github.com/OpenAPITools/openapi-generator/pull/1262
Swagger Code Generator: https://github.com/swagger-api/swagger-codegen/pull/8245
Suggest a fix/enhancement
The generated code, should look like as proposed in the following Stackoverflow answers:
https://stackoverflow.com/a/31321861
https://stackoverflow.com/a/31321821
https://stackoverflow.com/a/44628460
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
Start by reproducing the Java generation from the YAML schema in the description, then trace how schemas combining additionalProperties with properties are handled. Verify the generated Links model and its JSON serialization, using the expected behavior from the linked Stack Overflow examples as the completion criterion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100