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

Bug: Duplicate name object result in incorrect code generation #312

Closed
bibiboss opened this issue Jan 17, 2024 · 10 comments · Fixed by #329
Closed

Bug: Duplicate name object result in incorrect code generation #312

bibiboss opened this issue Jan 17, 2024 · 10 comments · Fixed by #329
Assignees
Labels
bug Something isn't working

Comments

@bibiboss
Copy link

Hello!

I have an issue using the plugin with asyncapi.
When I have sub-object with the same name, the plugin generates only one of them, even if they are differents.

Asyncapi:

asyncapi: 2.5.0
info:
  title: Component MQTT interface contract
  version: '1.0.0'
  description: |
    This document describe the input and output of the component

defaultContentType: application/json
channels:
  events/public/output/{organizationId}:
    description: The output topic
    parameters:
      organizationId:
        $ref: '#/components/parameters/organizationId'
    subscribe:
      operationId: output
      traits:
        - bindings:
            mqtt:
              retain: true
      message:
        $ref: '#/components/messages/output'
  events/public/input/{organizationId}:
    description: The input topic
    parameters:
      organizationId:
        $ref: '#/components/parameters/organizationId'
    publish:
      operationId: input
      traits:
        - bindings:
            mqtt:
              retain: true
      message:
        $ref: '#/components/messages/input'
components:
  messages:
    output:
      name: output
      title: Output message
      summary: bob
      contentType: application/json
      payload:
        $ref: "#/components/schemas/output"
    input:
      name: input
      title: input message
      summary: eve
      contentType: application/json
      payload:
        $ref: "#/components/schemas/input"
  schemas:
    input:
      type: object
      properties:
        source:
          type: string
          enum:
            - "input"
        data: # DATA Object first definition
          type: object
          properties:
            commitId:
              type: string
              examples:
                - "toto"
                - "tata"
    output:
      type: object
      properties:
        source:
          type: string
          enum:
            - "tenant"
        type:
          type: string
          enum:
            - "update"
            - "delete"
        data: # DATA object second definition
          type: object
          properties:
            tenantId:
              type: string
              examples:
                - tenant1
            name:
              type: string
              examples:
                - "hugues"
  parameters:
    organizationId:
      description: The identifier of an organization
      schema:
        type: string
        examples:
          - "toto"
          - "bob"

maven configuration:

            <plugin>
                <groupId>com.sngular</groupId>
                <artifactId>scs-multiapi-maven-plugin</artifactId>
                <version>5.3.1</version>
                <executions>
                    <execution>
                        <id>asyncapi</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>asyncapi-generation</goal>
                        </goals>
                        <configuration>
                            <specFiles>
                                <specFile>
                                    <filePath>${project.basedir}/asyncapi.yml</filePath>
                                    <consumer>
                                        <ids>input</ids>
                                        <apiPackage>test2.controller</apiPackage>
                                        <modelPackage>test2.model</modelPackage>
                                    </consumer>
                                    <supplier>
                                        <ids>output</ids>
                                        <apiPackage>test.provider</apiPackage>
                                        <modelPackage>test.model</modelPackage>
                                    </supplier>
                                </specFile>
                            </specFiles>
                            <generatedSourcesFolder>generated-sources</generatedSourcesFolder>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Result:
image

@jemacineiras
Copy link
Contributor

Hi @bibiboss,
Can you please clarify which one are you missing?
if you are talking about the input on, we are not generating message class since are not needed, as he code we generate you only need to send the payload.
Cheers

@bibiboss
Copy link
Author

bibiboss commented Jan 17, 2024

Hello @jemacineiras
When generating the code, the class test.test2.model.Input has a property Data data which is not generated. This result in a compilation error.

In test.test2.model.Input I have:
image

There is a missing object is supposed to be generated like

public class Data {
  @JsonProperty(value ="commitId")
  private String commitId;
  // more stuff
}

This definition is described in asyncapi in '#/components/schemas/input' line 80 to 90 in the example I provided.

Are you saying that this kind of definition won't be generated since it is configured in the supplier section?

EDIT: I changed a sentence, it was misconfusing

@jemacineiras
Copy link
Contributor

Hi @bibiboss,

Got it we will address that soon. Actually we are working in some refactor and probably that issue will be solve there.

Cheers.

@jemacineiras
Copy link
Contributor

Hi @bibiboss ,
Are you saying that this kind of definition won't be generated since it is configured in the supplier section?
No, I was thinking about duplicate Input definition, but this is not related to the duplicated definition. I need to double check it.
Cheers

@jemacineiras jemacineiras self-assigned this Jan 17, 2024
@jemacineiras jemacineiras added the bug Something isn't working label Jan 17, 2024
@bibiboss
Copy link
Author

bibiboss commented Feb 6, 2024

Hello @jemacineiras
Any updates on this one?

@rafaelgonzalezsimon rafaelgonzalezsimon self-assigned this Feb 6, 2024
@rafaelgonzalezsimon
Copy link
Contributor

Hi @bibiboss
We are still working on it. It looks like it needs some changes in .yml file processing code.

@rafaelgonzalezsimon
Copy link
Contributor

Hi @bibiboss ,
We have implemented a fix for this issuein this branch. 312-bug-duplicate-name-object-result-in-incorrect-code-generation

@bibiboss
Copy link
Author

Hello @rafaelgonzalezsimon

Sorry, I didn't got the notification. I'll try it out this week and give you feedback!

@bibiboss
Copy link
Author

Hello @rafaelgonzalezsimon
It still don't work :(
I'll create a github repo tommorow and reference it in here, so you can have a way to replicate.

@bibiboss
Copy link
Author

Hello @rafaelgonzalezsimon and @jemacineiras

I've created this repo.
Feel free to ping me if you need more details.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants