jsonschema2pojo
jsonschema2pojo copied to clipboard
Additional Properties Naming Conflict
This PR contains a failing test case for the following situation:
{
"type" : "object",
"properties": {
"additionalProperties": {
"type": "string"
}
},
"additionalProperties" : true
}
This is related to #607
java.lang.IllegalArgumentException: trying to create the same field twice: additionalProperties
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:425)
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:396)
at org.jsonschema2pojo.rules.AdditionalPropertiesRule.addAdditionalPropertiesField(AdditionalPropertiesRule.java:128)
at org.jsonschema2pojo.rules.AdditionalPropertiesRule.apply(AdditionalPropertiesRule.java:108)
at org.jsonschema2pojo.rules.AdditionalPropertiesRule.apply(AdditionalPropertiesRule.java:43)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:137)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:72)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:89)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:39)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:88)
at org.jsonschema2pojo.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:75)
at org.jsonschema2pojo.maven.Jsonschema2PojoMojo.execute(Jsonschema2PojoMojo.java:594)
@joelittlejohn I opened this because it also seemed to be the root cause of #607. I ran into it when trying to generate types for JSON Schema's schema. I took a stab at resolving it, but the existing strategy for naming fields does not leave room for the additionalProperties map to have a static name. Should I mark the test case as ignored, so the project can keep it as documentation?
Lets leave this here for now. I'm not a fan of ignored tests in the project.
I think this may be rare enough that it's not worth fixing, and given the further comments on #607 I'm not entirely convinced that this is the same problem (or more accurately, this may be the same problem but I'm not convinced it's what the reporter intended to achieve).
We could change the name of the additionalProperties field/getter/setter to increase the chance that it will be unique, but I don't think this is worth the disruption. We could also improve this by simply adding a better error message that explains the problem.