cli icon indicating copy to clipboard operation
cli copied to clipboard

Specfile with invalid examples considered valid

Open lovebug356 opened this issue 2 years ago • 13 comments

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 avatar Nov 27 '23 15:11 lovebug356

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 Nov 27 '23 15:11 github-actions[bot]

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

fmvilas avatar Nov 27 '23 15:11 fmvilas

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.

smoya avatar Nov 27 '23 16:11 smoya

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

lovebug356 avatar Nov 27 '23 16:11 lovebug356

@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)

PradeepJoshiFreelancer avatar Dec 06 '23 04:12 PradeepJoshiFreelancer

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

lovebug356 avatar Jan 18 '24 08:01 lovebug356

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?

lovebug356 avatar Jan 18 '24 08:01 lovebug356

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

PeteAudinate avatar Jan 29 '24 08:01 PeteAudinate

@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

peter-rr avatar Mar 20 '24 18:03 peter-rr

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.

Souvikns avatar Mar 21 '24 07:03 Souvikns

@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

smoya avatar Mar 21 '24 16:03 smoya

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

Amzani avatar Jul 05 '24 08:07 Amzani

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

Souvikns avatar Jul 25 '24 07:07 Souvikns

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 Nov 23 '24 00:11 github-actions[bot]