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] payload of type date shows validation error #980

Open
2 tasks done
Tracked by #1012
sam0r040 opened this issue Apr 5, 2024 · 3 comments
Open
2 tasks done
Tracked by #1012

[BUG] payload of type date shows validation error #980

sam0r040 opened this issue Apr 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@sam0r040
Copy link

sam0r040 commented Apr 5, 2024

Describe the bug.

AsyncAPI studio shows an error for data type date when YAML is used while data type datetime works fine.

Interestingly enough, if the date string is wrapped in double quotes, the validation error goes away.

Expected behavior

Validation passes for the provided yaml.

Screenshots

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:
  sendUserSignedup:
    action: send
    channel:
      $ref: '#/channels/userSignedup'
    messages:
      - $ref: '#/channels/userSignedup/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        required: 
          - displayName
          - date
          - dateTime
        examples: 
          - displayName: "ctest"
            date: 2015-07-20
            dateTime: 2015-07-20T15:49:04-07:00
        properties:
          displayName:
            type: string
            description: Name of the user
          date:
            type: string
            format: date
            description: Name of the user
          dateTime:
            type: string
            format: date-time
            description: Name of the user

How to Reproduce

  1. Got to https://studio.asyncapi.com/
  2. Paste the spec from above
  3. AsyncAPI studio shows the following error:
    44:23 "date" property must match format "date"

🥦 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 ?

No, someone else can work on it

@sam0r040 sam0r040 added the bug Something isn't working label Apr 5, 2024
Copy link

github-actions bot commented Apr 5, 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.

@smoya
Copy link
Member

smoya commented Apr 9, 2024

Hi @sam0r040!

The issue comes with the library we use for parsing YAML, which is js-yaml.
There are several issues opened on their repository talking about this. For example: nodeca/js-yaml#161

The summary is that, whenever that parser finds a field that is not an explicit string (without quotes), it fallbacks to some schemas. The default one is called "Core" , and is supposed to be based on YAML spec, so whenever it finds a value with the format of date, it transforms it into a datetime. Means, it transforms from 2015-07-20 to 2015-07-20T00:00:00.000Z.

As the first and quick solution, I encourage all those values to be enclosed with quotes.
However, I tested their recommendation of using other fallback schemas, in particular the JSON Schema one and the parser is able to parse properly without those errors.

loadedObj = yaml.load(asyncapi, { schema: yaml.JSON_SCHEMA });

All tests are passing, but not 100% sure if adding that could break other documents, so not sure if this possible fix would become a breaking change 🤔

cc @jonaslagoni @magicmatatjahu

@aeworxet
Copy link
Contributor

This bug gets fixed for both studio and studio-next by changes in packages:

Compiled directories used:

  • ./packages/parser/cjs for studio.
  • ./packages/parser/esm for studio-next.

image

All tests both in @stoplight/spectral-core and @asyncapi/parser pass with these changes.

Should I create PRs or might there be some hidden caveats?

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

3 participants