-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] [JAVA] "additionalProperties" does not generate a HashMap Model, openapi: 3.0.2 #7066
Comments
Please try the option |
Thanks for your answer @wing328 . I tried both
and
But none of them worked. How should I set the |
I think the first one should work ... |
@wing328 I realized if I define a Map of string to string in the yaml file like the following then
But if the value is an object or ref (which I need) like the the following then
or
|
Just to add, I do have the same issue on javascript side. Having the following version in my package.json
and running with |
It is slightly different issue in JAX-RS. I am working on v4.3.1 and OpenAPI v2 It generates Message.java but the pojo where messages are included does not have type information. This generates a compile error.
I traced it to below code on pojo.mustache
I am not sure how HashMap<> is getting substituted here. Please let me know if you want me to create a separate issue for this |
Can someone please answer this? |
@roostapour based on what you provided, looks like it's a bug. A good starting point is https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java and search for |
Hello, |
Confirmed that as of 4.3.1 classes are generated, but:
|
Any update on the issue? Is this fixed? Facing same issue |
Hi, |
@MarcelHoell @arvindkrishnakumar-okta For each of you, does the non-working Java class that OpenAPI Generator produces contain |
The OpenAPI definition is amended and the annotation schmea replaced by a plain object definition because of a bug in the openapi generator: OpenAPITools/openapi-generator#7066
The OpenAPI definition is amended and the annotation schmea replaced by a plain object definition because of a bug in the openapi generator: OpenAPITools/openapi-generator#7066
Update to Gradle Plugin version 6.4.0 resolved problem |
Still exists with maven plugin >6.3.0 Tested with 6.4, 6.5 and 6.6 api-spec.yaml: description:
type: object
nullable: true
description: description of the object
additionalProperties:
type: string
example:
de: Wurst
en: sausage generated java code (tested with 6.4, 6.5, 6.6): /**
* description of the object
**/
@JsonbProperty("description")
private Map<String, String> description = ; generated code with 6.3.0: /**
* description of the object
**/
@JsonbProperty("description")
private Map<String, String> description = null; pom.xml (working config): <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.3.0</version>
<executions>
<execution>
<id>generate-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>java</generatorName>
<generateAliasAsModel>true</generateAliasAsModel> <-- has no effect though, can be omitted
</configuration>
</execution>
</executions>
</plugin> |
can you please test with the latest master? I did a test but couldn't repeat the issue. The output compiles fine. |
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. |
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. |
My workaround: string-replace
For each line that needs replacement, add an execution |
Still having this issue in 2024. Sad to see it not picked up at all. |
I tried with 7.0.0 and 7.3.0 versions and bug seems solved (with 6.6.0 I had the problem). |
Description
I am using "additionalProperties" in my yaml file as below.
But when running
mvn clean package
, no class is being created for Messages. I was expecting to see a class like :in
org.openapitools.client.model.Messages
the same as other classes generated based on the yaml file. I triedadditionalProperties: true
andadditionalProperties: {}
but none of them worked. It seems like a bugmy pom.xml for openapi-generator and swagger versions
Command line used for generation
mvn clean package
The text was updated successfully, but these errors were encountered: