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] Parsing AsyncAPI with Refs (Avro schemas) the schemaFormat and schema is now what is expected #289

Open
2 tasks done
boyney123 opened this issue Nov 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@boyney123
Copy link

boyney123 commented Nov 4, 2024

Describe the bug.

I have a very basic AsyncAPI file

asyncapi: 3.0.0
info:
  title: Streetlights App
  version: '1.0.0'
  description: |
    The Smartylighting Streetlights application allows you
    to remotely manage the city lights.
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'
servers:
  mosquitto:
    host: test.mosquitto.org
    protocol: mqtt
channels:
  lightMeasuredAvro:
    address: 'light/measuredavro'
    messages:
      lightMeasuredMessageAvro:
        name: LightMeasuredAvro
        payload:
          schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
          schema:
            $ref: "./schema.avro"
operations:
  receiveAvro:
    action: 'receive'
    summary: Information about environmental lighting conditions for a particular streetlight.
    channel:
      $ref: '#/channels/lightMeasuredAvro'

This references an avro schema:

{
  "type": "record",
  "name": "UserCreated",
  "namespace": "com.example.events",
  "fields": [
    {
      "name": "id",
      "type": "string",
      "doc": "User identifier"
    },
    {
      "name": "email",
      "type": "string",
      "doc": "User's email address"
    },
    {
      "name": "createdAt",
      "type": "long",
      "doc": "Timestamp of user creation",
      "logicalType": "timestamp-millis"
    },
    {
      "name": "isActive",
      "type": "boolean",
      "default": true
    }
  ]
}

When I use the parser, I want to get a generated document (with refs parsed), which is working, but the output is not a valid AsyncAPI file?

{
    "asyncapi": "3.0.0",
    "info": {
        "title": "Streetlights App",
        "version": "1.0.0",
        "description": "The Smartylighting Streetlights application allows you\nto remotely manage the city lights.\n",
        "license": {
            "name": "Apache 2.0",
            "url": "https://www.apache.org/licenses/LICENSE-2.0"
        }
    },
    "servers": {
        "mosquitto": {
            "host": "test.mosquitto.org",
            "protocol": "mqtt"
        }
    },
    "channels": {
        "lightMeasuredAvro": {
            "address": "light/measuredavro",
            "messages": {
                "lightMeasuredMessageAvro": {
                    "name": "LightMeasuredAvro",
                    "payload": {
                        "schemaFormat": "application/vnd.apache.avro;version=1.9.0",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id",
                                "email",
                                "createdAt"
                            ],
                            "properties": {
                                "id": {
                                    "type": "string",
                                    "description": "User identifier",
                                    "x-parser-schema-id": "<anonymous-schema-1>"
                                },
                                "email": {
                                    "type": "string",
                                    "description": "User's email address",
                                    "x-parser-schema-id": "<anonymous-schema-2>"
                                },
                                "createdAt": {
                                    "type": "integer",
                                    "minimum": -9223372036854776000,
                                    "maximum": 9223372036854776000,
                                    "description": "Timestamp of user creation",
                                    "x-parser-schema-id": "<anonymous-schema-3>"
                                },
                                "isActive": {
                                    "type": "boolean",
                                    "default": true,
                                    "x-parser-schema-id": "<anonymous-schema-4>"
                                }
                            },
                            "x-parser-schema-id": "com.example.events.UserCreated"
                        },
                        "x-parser-original-payload": {
                            "type": "record",
                            "name": "UserCreated",
                            "namespace": "com.example.events",
                            "fields": [
                                {
                                    "name": "id",
                                    "type": "string",
                                    "doc": "User identifier"
                                },
                                {
                                    "name": "email",
                                    "type": "string",
                                    "doc": "User's email address"
                                },
                                {
                                    "name": "createdAt",
                                    "type": "long",
                                    "doc": "Timestamp of user creation",
                                    "logicalType": "timestamp-millis"
                                },
                                {
                                    "name": "isActive",
                                    "type": "boolean",
                                    "default": true
                                }
                            ]
                        }
                    },
                    "x-parser-unique-object-id": "lightMeasuredMessageAvro"
                }
            },
            "x-parser-unique-object-id": "lightMeasuredAvro"
        }
    },
    "operations": {
        "receiveAvro": {
            "action": "receive",
            "summary": "Information about environmental lighting conditions for a particular streetlight.",
            "channel": {
                "address": "light/measuredavro",
                "messages": {
                    "lightMeasuredMessageAvro": {
                        "name": "LightMeasuredAvro",
                        "payload": {
                            "schemaFormat": "application/vnd.apache.avro;version=1.9.0",
                            "schema": {
                                "type": "object",
                                "required": [
                                    "id",
                                    "email",
                                    "createdAt"
                                ],
                                "properties": {
                                    "id": {
                                        "type": "string",
                                        "description": "User identifier",
                                        "x-parser-schema-id": "<anonymous-schema-1>"
                                    },
                                    "email": {
                                        "type": "string",
                                        "description": "User's email address",
                                        "x-parser-schema-id": "<anonymous-schema-2>"
                                    },
                                    "createdAt": {
                                        "type": "integer",
                                        "minimum": -9223372036854776000,
                                        "maximum": 9223372036854776000,
                                        "description": "Timestamp of user creation",
                                        "x-parser-schema-id": "<anonymous-schema-3>"
                                    },
                                    "isActive": {
                                        "type": "boolean",
                                        "default": true,
                                        "x-parser-schema-id": "<anonymous-schema-4>"
                                    }
                                },
                                "x-parser-schema-id": "com.example.events.UserCreated"
                            },
                            "x-parser-original-payload": {
                                "type": "record",
                                "name": "UserCreated",
                                "namespace": "com.example.events",
                                "fields": [
                                    {
                                        "name": "id",
                                        "type": "string",
                                        "doc": "User identifier"
                                    },
                                    {
                                        "name": "email",
                                        "type": "string",
                                        "doc": "User's email address"
                                    },
                                    {
                                        "name": "createdAt",
                                        "type": "long",
                                        "doc": "Timestamp of user creation",
                                        "logicalType": "timestamp-millis"
                                    },
                                    {
                                        "name": "isActive",
                                        "type": "boolean",
                                        "default": true
                                    }
                                ]
                            }
                        },
                        "x-parser-unique-object-id": "lightMeasuredMessageAvro"
                    }
                },
                "x-parser-unique-object-id": "lightMeasuredAvro"
            },
            "x-parser-unique-object-id": "receiveAvro"
        }
    },
    "x-parser-spec-parsed": true,
    "x-parser-api-version": 3
}

If you upload this to https://studio.asyncapi.com/, you can see the issues. The payload of the schema is not what it expects... I believe with the "schemaFormat": "application/vnd.apache.avro;version=1.9.0", it should be something like this...

{
  "asyncapi": "3.0.0",
  "info": {
    "title": "Streetlights App",
    "version": "1.0.0",
    "description": "The Smartylighting Streetlights application allows you\nto remotely manage the city lights.\n",
    "license": {
      "name": "Apache 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "servers": {
    "mosquitto": {
      "host": "test.mosquitto.org",
      "protocol": "mqtt"
    }
  },
  "channels": {
    "lightMeasuredAvro": {
      "address": "light/measuredavro",
      "messages": {
        "lightMeasuredMessageAvro": {
          "name": "LightMeasuredAvro",
          "payload": {
            "schemaFormat": "application/vnd.apache.avro;version=1.9.0",
            "schema": {
              "type": "record",
              "name": "UserCreated",
              "namespace": "com.example.events",
              "fields": [
                {
                  "name": "id",
                  "type": "string",
                  "doc": "User identifier"
                },
                {
                  "name": "email",
                  "type": "string",
                  "doc": "User's email address"
                },
                {
                  "name": "createdAt",
                  "type": "long",
                  "doc": "Timestamp of user creation",
                  "logicalType": "timestamp-millis"
                },
                {
                  "name": "isActive",
                  "type": "boolean",
                  "default": true
                }
              ]
            }
          }
        }
      }
    }
  },
  "operations": {
    "receiveAvro": {
      "action": "receive",
      "summary": "Information about environmental lighting conditions for a particular streetlight.",
      "channel": {
        "$ref": "#/channels/lightMeasuredAvro"
      }
    }
  }
}

Not sure I'm doing something wrong? But how can I tell the parser to use the x-parser-original-payload in the output of the document?

Expected behavior

See above

Screenshots

N/A

How to Reproduce

Explained above.

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

@boyney123 boyney123 added the bug Something isn't working label Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

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.

@boyney123
Copy link
Author

Ah ignore this, I just found out you can parse and ignore schemas from being parsed

 const { document, diagnostics } = service.path.startsWith('http')
      ? await fromURL(parser, service.path).parse()
      : await fromFile(parser, service.path).parse({
        parseSchemas: false,
      });

Closing this, but for anyone looking, this can help!

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

No branches or pull requests

1 participant