swagger-api / swagger-api/swagger-codegen
[Java] Compilation error with model containing with Map<String, Set<enum>>
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am able to run swagger codegen with 2.1.5 but there are bugs which break codgen until master when you have a model containing a container with an enum embedded in another container.
Swagger-codegen version
Worked in 2.1.5 as the enum evaluated to just a string
2.1.6 - broken for other reasons
2.2.2-SNAPSHOT, still broken
Swagger declaration file content or url
Java class with annotation
@ApiModel (value = "MyModel", description = "My model description")
public class MyModel {
@ApiModel
public enum MyEnum {
VALUE1,VALUE2,VALUE3
}
@JsonProperty("my_property")
@ApiModelProperty (value = "my property description")
private Map<String, Set<MyEnum>> breakingProperty;
@JsonCreator
public MyModel(@JsonProperty ("my_property") Map<String, Set<MyEnum>> property) {
breakingProperty = breakingProperty;
}
}
"MyModel" : {
"type" : "object",
"properties" : {
"my_property" : {
"type" : "object",
"description" : "my property description",
"additionalProperties" : {
"type" : "array",
"uniqueItems" : true,
"items" : {
"type" : "string",
"enum" : [ "VALUE1", "VALUE2", "VALUE3" ]
}
}
}
}
Command line used for generation
Using the maven plugin with the java jersey2 libraries and joda as a date library
Steps to reproduce
- Get the swagger.json file generated from the jetty server
- Run codegen from the generated spec
- Compilation fails
Related issues
https://github.com/swagger-api/swagger-codegen/issues/3450
This fixed an array with an enum but not when it is nested.
Suggest a Fix
At this time, I don't have one, I need to do some more work to step through and debug the code. Basically something in the template is causing the generated code to produce an InnerEnum reference without defining it. The original enum never gets generated for some reason. Also there is an issue referencing it as well. I'm not 100% sure this is a problem with codegen, it also might be with generating the spec from the annotation library as well. When I get a chance, I will be trying to isolate that.
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 with the generated swagger.json and the Java Jersey2 Maven generation described in the report, focusing on the nested Map<String, Set> property. Compare the generated code with the reported InnerEnum reference and missing original enum. Done means the generated Java code compiles with the nested enum structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100