parser-js icon indicating copy to clipboard operation
parser-js copied to clipboard

Referencing AsyncAPI specs to reuse messages and schemas generates Java classes with incorrect names

Open manoswerts opened this issue 3 years ago • 8 comments

Describe the bug

When generating Java code from an AsyncAPI spec which references another one for reuse, schemas from the referenced AsyncAPI spec are named AnonymousSchema<#>.java instead of using the schema name.

Java classes are generated correctly for schema's in the main AsyncAPI spec.

How to Reproduce

Ensure that you have 2 AsyncAPI specs of which one references the other to reuse a message.

asyncapi.yaml

channels:
  user.update:
    publish:
      summary: User is updated
      message:
        $ref: '<url-or-path-to-other-asyncapi-yaml>l#/components/messages/user'

other-asyncapi.yaml

components:
    messages:
        user:
            contentType: 'application/json'
        payload:
            $ref: '#/components/schemas/User'

  schemas:
      User:
          type: object
          properties:
              [...]

Execute ag asyncapi.yaml @asyncapi/java-spring-template

Expected behavior

A Java class is generated for schema User called User.java.

manoswerts avatar Jul 09 '21 10:07 manoswerts

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Sep 08 '21 00:09 github-actions[bot]

I think we can move this to https://github.com/asyncapi/java-spring-template as it has nothing to do with the generator itself.

jonaslagoni avatar Sep 21 '21 11:09 jonaslagoni

In theory now that I think about it, it might actually be related to the parser more so, as this template just uses what is determined by the parser: https://github.com/asyncapi/java-spring-template/blob/9fccfdee2bbc20f7452e5f2f5fabe1fa6e3a2e30/template/src/main/java/com/asyncapi/model/%24%24objectSchema%24%24.java#L17

jonaslagoni avatar Sep 21 '21 11:09 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Jan 20 '22 00:01 github-actions[bot]

Oh, it actually is a parser bug:

take these files:

#asyncapi.yml
asyncapi: 2.0.0
info:
  title: My API
  version: '1.0.0'
channels:
  mychannel:
    publish:    
      message:
        $ref: 'refed.yml#/components/messages/testMessage'
#refed.yml
components:
  messages:
    testMessage:
      payload:
        $ref: '#/components/schemas/testSchema'
  schemas:
    testSchema:
      type: object
      properties:
        name:
          type: string

and you get this:

{
    "asyncapi": "2.0.0",
    "info": {
        "title": "My API",
        "version": "1.0.0"
    },
    "channels": {
        "mychannel": {
            "publish": {
                "message": {
                    "payload": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "x-parser-schema-id": "<anonymous-schema-2>"
                            }
                        },
                        "x-parser-schema-id": "<anonymous-schema-1>"
                    },
                    "x-parser-original-schema-format": "application/vnd.aai.asyncapi;version=2.0.0",
                    "x-parser-original-payload": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string"
                            }
                        }
                    },
                    "schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0",
                    "x-parser-message-parsed": true,
                    "x-parser-message-name": "<anonymous-message-1>"
                }
            }
        }
    },
    "x-parser-spec-parsed": true
}

so of course result.channel('mychannel').publish().message().payload().uid() returns <anonymous-schema-1> instead of testSchema

btw I wish to one day do something like result.getSchemaId(messageId) or at least result.getSchema(messageId).uid() instead of result.channel('mychannel').publish().message().payload().uid() 😄 (intent-driven API fan here)

derberg avatar Jan 20 '22 18:01 derberg

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Jan 20 '22 18:01 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar May 21 '22 00:05 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 21 '22 00:09 github-actions[bot]

Can confirm this is related to parser and external references. We see same issue with a JavaScript based code generator. Works fine when the definition is directly embedded in the schema, but when referenced to another file it blows up as result of the “anonymous” factor.

dvins avatar Nov 14 '22 17:11 dvins

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Mar 15 '23 00:03 github-actions[bot]