openapi-generator: [BUG] [JAVA] "additionalProperties" does not generate a HashMap Model, openapi: 3.0.2
Description
I am using “additionalProperties” in my yaml file as below.
openapi: 3.0.2
....
components:
schemas:
Messages:
type: object
additionalProperties:
$ref: '#/components/schemas/Message'
Message:
type: object
properties:
code:
type: integer
text:
type: string
But when running mvn clean package, no class is being created for Messages. I was expecting to see a class like :
public class Messages extends HashMap<String, Object> {
......
}
in org.openapitools.client.model.Messages the same as other classes generated based on the yaml file. I tried additionalProperties: true and additionalProperties: {} but none of them worked. It seems like a bug
my pom.xml for openapi-generator and swagger versions
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.1</version>
</dependency>
....
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
...
</execution>
</executions>
</plugin>
Command line used for generation
mvn clean package
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 23 (5 by maintainers)
Commits related to this issue
- MGDCTRS-1752: Update openapi definitions The OpenAPI definition is amended and the annotation schmea replaced by a plain object definition because of a bug in the openapi generator: https://gith... — committed to lburgazzoli/bf2-cos-fleetshard by lburgazzoli 2 years ago
- MGDCTRS-1752: Update openapi definitions The OpenAPI definition is amended and the annotation schmea replaced by a plain object definition because of a bug in the openapi generator: https://gith... — committed to bf2fc6cc711aee1a0c2a/cos-fleetshard by lburgazzoli 2 years ago
Any updates? I tried it with openapi-generator-maven-plugin 5.4.0. and get an compile time error. When adding an item to the hashmap it tries to initialize the Map. Here’s a snippet of the generated code:
If my understanding is correct, currently it’s not possible to have additionalProperties of type object to work in the current java client generator. I do not see any intention to move this forward in the past years — is it a rarely required functionality? Because we sure need it.
Hi, Did you solve this issue how to remove that hashMap how it is substituting.i am also stuck at this problem and I am using open api 5.1.0 version
Hello, We have a similar issue trying to generate a Map from our YAML file (v3). Is there a document/example on how to generate maps/dictionaries properly?
My workaround: string-replace
For each line that needs replacement, add an execution
HashMap generation (https://swagger.io/docs/specification/data-models/dictionaries/) in java works in 5.0.0-beta2 version, but is broken in 6.6.0 version.
I’ve got the same problem…