sngular/scs-multiapi-plugin

Bug: Duplicate name object result in incorrect code generation

Closed this issue · 10 comments

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

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

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

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.

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

Hello @jemacineiras
Any updates on this one?

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

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

Hello @rafaelgonzalezsimon

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

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.

Hello @rafaelgonzalezsimon and @jemacineiras

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

Best regards.