Skip to content
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

OpenAPI Generator - entities are generating duplicated mapping keys #2172

Closed
philbuettner opened this issue Dec 11, 2019 · 11 comments
Closed
Assignees
Milestone

Comments

@philbuettner
Copy link
Contributor

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

@t-gauss
Copy link
Contributor

t-gauss commented Jan 10, 2020

I'll look into it.

@mschoeffler
Copy link

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

@t-gauss
Copy link
Contributor

t-gauss commented Jan 17, 2020

Thanks for the hint and thanks @philbuettner for providing the models. I need to ask a beginner question since I'm new to the topic: I tried to reproduce this but the only way I was able to was by creating an entity with two properties having the same ID. Is this the problem which is described here? In the example information models I cannot see this.

@philbuettner
Copy link
Contributor Author

I don't know why, but I can't reproduce this behaviour anymore with the official current Vorto release.

@philbuettner
Copy link
Contributor Author

Thanks for the hint and thanks @philbuettner for providing the models. I need to ask a beginner question since I'm new to the topic: I tried to reproduce this but the only way I was able to was by creating an entity with two properties having the same ID. Is this the problem which is described here? In the example information models I cannot see this.

This error occured with a unique property id.

@t-gauss
Copy link
Contributor

t-gauss commented Jan 17, 2020

Hello @mschoeffler ,
could you let me know in which scenario you encounter this problem? Does it happen with unique property IDs as well?

@mschoeffler
Copy link

Hi, the bug occurs with any model configuration, including unique properties. I just tried it out with a very basic infomodel --> vorto.private.mschoeffler.temp_Test_1.0.0.zip

In order to reproduce the bug, I go to information model and start the Open API Generator from there. The generated file has a duplicate of 'temperature':

    TestEntity:
      type: object
      properties:
        temperature:
          type: number
        temperature:
          type: number
      required: [temperature]

I did my test on the current code basis --> 19.01.20, commit 86de67a

My guess is that the bug occurs while parsing/importing the Vorto model. I did only a very brief debugging: getFlatStatusProperties seems to add a duplicate to the entity (line 212). Not something that I would have expected from a "get method".

https://github.com/eclipse/vorto/blob/f065ac8f833e2c3a9789a784816277e11de95807/core-bundles/meta-model/org.eclipse.vorto.core/src/org/eclipse/vorto/core/api/model/ModelConversionUtils.java#L212

@t-gauss
Copy link
Contributor

t-gauss commented Jan 20, 2020

Hello @mschoeffler ,
many thanks for the example model. When I do this in my local dev environment I don't see this issue. I will look into it.

@t-gauss
Copy link
Contributor

t-gauss commented Jan 20, 2020

Hello @mschoeffler ,
I tried this in the production environment. Even there it is working. It seems to be a problem with the generator runner.

@t-gauss
Copy link
Contributor

t-gauss commented Jan 27, 2020

PR here
Seems as if this was introduced in October 2019. I changed it as suggested by @mschoeffler - thanks for the hint.

@t-gauss
Copy link
Contributor

t-gauss commented Jan 27, 2020

Added another commit. The contraint rules were omitted previously.

t-gauss pushed a commit to bosch-io/vorto that referenced this issue Jan 27, 2020
@kolotu kolotu closed this as completed in 71864ea Jan 29, 2020
kolotu added a commit that referenced this issue Jan 29, 2020
…pingKeys

Prevent properties from being added multiple times. Fixes #2172
JulianFeinauer pushed a commit to JulianFeinauer/vorto that referenced this issue Jun 27, 2020
JulianFeinauer pushed a commit to JulianFeinauer/vorto that referenced this issue Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants