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

Fix schema type of AsyncAPI operation tags #1339

Merged
merged 3 commits into from
Dec 28, 2023

Conversation

shishkin
Copy link
Contributor

@shishkin shishkin commented Nov 23, 2023

What/Why/How?

Tags type on operation and operation trait wasn't using available TagList type that other elements used.

Reference

https://www.asyncapi.com/docs/reference/specification/v2.6.0#tagObject

Testing

Added an example of operation with tags for linting.

Screenshots (optional)

N/A

Check yourself

  • Code is linted
  • Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@shishkin shishkin requested a review from a team as a code owner November 23, 2023 15:43
Copy link

changeset-bot bot commented Nov 23, 2023

🦋 Changeset detected

Latest commit: 6f2a72d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lornajane
Copy link
Contributor

The tests are here: https://github.com/Redocly/redocly-cli/tree/main/__tests__/lint/async2 - but they're really just the examples supplied by the AsyncAPI project to make sure we're not breaking anything.

Tags do not work the same way in OpenAPI (where they are defined at the top level and then used in the operations) and in AsyncAPI (where they are more freeform within each operation or trait), which is why the objects aren't re-used. Could you say something about your use case and if you saw a problem with the AsyncAPI linting?

@shishkin
Copy link
Contributor Author

Yes, I tried to lint a valid AsyncAPI spec and got a bunch of errors like this:

{
  "ruleId": "spec",
  "severity": "warn",
  "message": "Expected type `string` but got `object`.",
  "location": [
    {
      "source": {
        "absoluteRef": "/",
        "body": "..."
      },
      "pointer": "#/channels/my-channel/publish/tags/0",
      "reportOnKey": false
    }
  ],
  "suggest": []
}

The AsyncAPI spec I linked in the PR doesn't separate tag definition and usage. An example of an operation with tags from the spec is as follows:

operationId: registerUser
summary: Action to sign a user up.
description: A longer description
security:
  - petstore_auth:
    - write:pets
    - read:pets
tags:
  - name: user
  - name: signup
  - name: register
message:
  headers:
    type: object
    properties:
      applicationInstanceId:
        description: Unique identifier for a given instance of the publishing application
        type: string
  payload:
    type: object
    properties:
      user:
        $ref: "#/components/schemas/userCreate"
      signup:
        $ref: "#/components/schemas/signup"
bindings:
  amqp:
    ack: false
traits:
  - $ref: "#/components/operationTraits/kafka"

@shishkin
Copy link
Contributor Author

I've added a test that passes with this change, but fails if the change is reverted.

Copy link
Contributor

@lornajane lornajane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the pull request, the explanation and the test. It took us a while to verify, so thanks for your patience!

@lornajane lornajane merged commit b4c1274 into Redocly:main Dec 28, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants