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

Add rule to identify orphaned channel components #2098

Closed
jonaslagoni opened this issue Mar 17, 2022 · 1 comment
Closed

Add rule to identify orphaned channel components #2098

jonaslagoni opened this issue Mar 17, 2022 · 1 comment
Labels
AsyncAPI Issues related to the AsyncAPI ruleset good first issue Good for newcomers

Comments

@jonaslagoni
Copy link
Collaborator

jonaslagoni commented Mar 17, 2022

User story.
As a user, I can detect if my document has orphaned channels inside components.

Describe the solution you'd like
This should be a valid AsyncAPI file:

{
  asyncapi: '2.3.0',
  channels: {
    'users/signedUp': {
      $ref: '#/components/channels
    },
  },
  components: {
    channels: {
      userSignedUp: {
        subscribe: {
          message: {
            payload: {
              type: 'string',
            },
          },
        },
      },
    },
  },
}

The new ruleset should catch this invalid case:

{
  asyncapi: '2.3.0',
  channels: {},
  components: {
    channels: {
      userSignedUp: {
        subscribe: {
          message: {
            payload: {
              type: 'string',
            },
          },
        },
      },
    },
  },
}

In order to solve this you need to do the following steps:

  1. Add the new rule to the AsyncAPI ruleset: https://github.com/stoplightio/spectral/blob/develop/packages/rulesets/src/asyncapi/index.ts
  2. Add a test for the new rule: https://github.com/stoplightio/spectral/blob/develop/packages/rulesets/src/asyncapi/__tests__/asyncapi-unused-components-schema.test.ts
  3. Add the rule to the documentation: https://github.com/stoplightio/spectral/docs/reference/asyncapi-rules.md

Additional context
Part of #1103
Related PR that can be used as an example: #2097

@jonaslagoni jonaslagoni added good first issue Good for newcomers AsyncAPI Issues related to the AsyncAPI ruleset labels Mar 17, 2022
@jonaslagoni
Copy link
Collaborator Author

Closing as we create one rule for all instead, as OpenAPI has: #1103 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AsyncAPI Issues related to the AsyncAPI ruleset good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant