OpenAPI Generator - entities are generating duplicated mapping keys
See original GitHub issueWhen generating OpenAPI documents, in some documents the following error appears: Parser error - duplicated mapping key
This error only appears in connection with an entity object inside of a .type model. Because the OpenAPI Generator Template function, which parses entities did not changed from current release (0.12.4) to development branch, the cause of that error must be somewhere else (in 0.12.4 this error does not appear).
generates this error in the development branch:
Incident:
type: object
properties:
incidentType:
$ref: '#/components/schemas/IncidentType'
roomId:
type: string
timeOfIncident:
$ref: '#/components/schemas/DateTime'
~~~ Parser error - duplicated mapping key
incidentType:
$ref: '#/components/schemas/IncidentType'
roomId:
type: string
timeOfIncident:
$ref: '#/components/schemas/DateTime'
The following OpenAPI documents are containing the duplicated keys. If you compare them with each other, there are also slightly different in the block order. Documents which are generated correctly, always have the same order. But I am not sure if this was by coincident.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Gets duplicated mapping key error using openapi 3.0
I am trying to define my APIs using openapi version 3.0.0 . I've generated ...
Read more >Duplicate attributes when using '@' | Open APIs
When generating models using the Swagger definition using the swagger-codegen-maven-plugin (v2.3.1), there are some entities where the use ...
Read more >Usage - OpenAPI Generator
generate Generate code with the specified generator. help Display help information about openapi-generator. list Lists the available generators.
Read more >OpenAPI Specification - Version 3.0.3 - Swagger
When this is true, property values of type array or object generate separate parameters for each value of the array, or key-value-pair of...
Read more >Ords Parser error duplicated mapping key - swagger
Both POST handlers have input parameters. I can successfully generate the swagger/OpenAPI doc/clients.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Not sure if still required, but maybe it helps to find the actual problem: @bboersig and I came also across this bug. The problem is that “entity.properties”… https://github.com/eclipse/vorto/blob/2657685397bcf9a0f361843d8508fffcead3eef2/generators/generator-openapi/src/main/java/org/eclipse/vorto/codegen/openapi/templates/OpenAPITemplate.xtend#L615 … has the doubled amount of properties as expected.
When digging deeper, we saw that org.eclipse.vorto.plugin.utils.Utils.getReferencedEntities… https://github.com/eclipse/vorto/blob/2657685397bcf9a0f361843d8508fffcead3eef2/generators/generator-openapi/src/main/java/org/eclipse/vorto/codegen/openapi/Utils.xtend#L45 …returns indeed duplicates.
As far as I remember, the only difference between these duplicates is that the presence field is set only for one duplicate and the constraint rule field only for the other one.
As we were doing only some prototyping, we applied a hotfix by simply filtering the properties collection (generator code level) --> “entities.properties.filter[presence !== null]”. Btw. we took the idea of this hotfix from here: https://github.com/eclipse/vorto/blob/2657685397bcf9a0f361843d8508fffcead3eef2/generators/generator-openapi/src/main/java/org/eclipse/vorto/codegen/openapi/Utils.xtend#L72
Added another commit. The contraint rules were omitted previously.