question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI Generator - entities are generating duplicated mapping keys

See original GitHub issue

When 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).

This function: https://github.com/eclipse/vorto/blob/2657685397bcf9a0f361843d8508fffcead3eef2/generators/generator-openapi/src/main/java/org/eclipse/vorto/codegen/openapi/templates/OpenAPITemplate.xtend#L615

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.

OpenAPIgeneratedWithDuplicatedKeys.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
mschoefflercommented, Jan 17, 2020

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

0reactions
t-gausscommented, Jan 27, 2020

Added another commit. The contraint rules were omitted previously.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found