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

Specfile with invalid examples considered valid #925

Open
lovebug356 opened this issue Nov 27, 2023 · 13 comments
Open

Specfile with invalid examples considered valid #925

lovebug356 opened this issue Nov 27, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@lovebug356
Copy link
Contributor

lovebug356 commented Nov 27, 2023

A specfile with invalid examples is considered a valid specfile when validated with asyncapi validate.

This issue can be reproduced with following example. This file contains an invalid example (missing required field):

asyncapi: 3.0.0
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  userSignedUp:
    address: user/signedup
    messages:
      UserSignedUp:
        $ref: '#/components/messages/UserSignedUp'
operations:
  onUserSignUp:
    action: receive
    channel:
      $ref: '#/channels/userSignedUp'
    messages:
      - $ref: '#/channels/userSignedUp/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      examples:
        - name: Invalid Example
          summary: Example is missing required field email
          payload:
            displayName: My Name
      payload:
        type: object
        required: [displayName, email]
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user
@lovebug356 lovebug356 added the bug Something isn't working label Nov 27, 2023
Copy link
Contributor

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.

@fmvilas
Copy link
Member

fmvilas commented Nov 27, 2023

I think it would be interesting to have a flag in the CLI. Something like asyncapi validate --skip-examples.

@smoya
Copy link
Member

smoya commented Nov 27, 2023

What version of the parser are you using?

I believed the following Spectral rule takes care of such a validation https://github.com/asyncapi/parser-js/blob/master/src/ruleset/v2/ruleset.ts#L119 🤔

I'm afk, so I can't check this atm.

@lovebug356
Copy link
Contributor Author

I'm trying with the latest git version of cli and studio. According to npm, they are using this version:
@asyncapi/[email protected]

@PradeepJoshiFreelancer
Copy link

@lovebug356 - Can you please check the YML provided, on validating its giving an error at line #18
18:9 error asyncapi3-operation-messages-from-referred-channel Operation message does not belong to the specified channel. operations.user/signedup.subscribe.messages[0]

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)

If I try to uncomment the refrence to "UserSignedUp" it errors at a later line:
21:18 error asyncapi-document-resolved "messages" property type must be array components.messages.UserSignedUp

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)

@lovebug356
Copy link
Contributor Author

@PradeepJoshiFreelancer : Updated the example (adapted file generated by asyncapi new file).

@lovebug356
Copy link
Contributor Author

What version of the parser are you using?

I believed the following Spectral rule takes care of such a validation https://github.com/asyncapi/parser-js/blob/master/src/ruleset/v2/ruleset.ts#L119 🤔

I'm afk, so I can't check this atm.

I see you point to a spectral rule in v2 ruleset. I don't see something similar in v3 ruleset. Could it be that it is only supported for v2 at the moment?

@PeteAudinate
Copy link

I think that's right: it worked in v2 but the tools currently aren't validating examples in v3.

@peter-rr
Copy link
Member

peter-rr commented Mar 20, 2024

@lovebug356 @PeteAudinate That's right, this example is correctly validated for v2, but not for v3.

@smoya Tested with:

  • @asyncapi/cli: v1.7.0
  • @asyncapi/parser: v3.0.9

@Souvikns
Copy link
Member

Studio is not throwing any error so looks like this is a valid document. Also according to v3 schema exampels should have either payload or headers. If it has any one of those it should be valid.

@smoya
Copy link
Member

smoya commented Mar 21, 2024

@lovebug356 @PeteAudinate That's right, this example is correctly validated for v2, but not for v3.

@smoya Tested with:

  • @asyncapi/cli: v1.7.0
  • @asyncapi/parser: v3.0.9

Yeah, I confirm there is no such rule in place in the Parser for v3 of the spec.

Can any of the maintainers of this repo move this issue to the parser-js repository? cc @Souvikns @magicmatatjahu @derberg

@Amzani
Copy link
Collaborator

Amzani commented Jul 5, 2024

@smoya I can't
Screenshot 2024-07-05 at 10 19 13
You can try on your side

@Souvikns
Copy link
Member

Souvikns commented Jul 25, 2024

I can't either, only transfer issues between glee, CLI and bundler.

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
Status: Backlog
Development

No branches or pull requests

8 participants