[BUG] payload of type date shows validation error
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
- Got to https://studio.asyncapi.com/
- Paste the spec from above
- AsyncAPI studio shows the following error:
44:23 "date" property must match format "date"
🥦 Browser
None
👀 Have you checked for similar open issues?
- [X] I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- [X] I have read the Contributing Guidelines
Are you willing to work on this issue ?
No, someone else can work on it
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.
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: https://github.com/nodeca/js-yaml/issues/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
This bug gets fixed for both studio and studio-next by changes in packages:
-
@stoplight/spectral-corehttps://github.com/stoplightio/spectral/blob/develop/packages/core/package.json#L46- "ajv": "^8.6.0", + "ajv": "^8.17.1",https://github.com/stoplightio/spectral/commit/4b4b46e33b07225cba206c91555c7e97305ab94b (changes in other packages are required to build
spectral) -
@asyncapi/parserhttps://github.com/asyncapi/parser-js/blob/master/packages/parser/package.json#L57- "ajv": "^8.11.0", + "ajv": "^8.17.1",https://github.com/asyncapi/parser-js/commit/4a9fd5c4fca979ef680df1a634fc2f24026837fe
Compiled directories used:
-
./packages/parser/cjsforstudio. -
./packages/parser/esmforstudio-next.
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?
It is assumed that an update of a minor version is unlikely to break anything, so the change to @stoplight/spectral-core is submitted as the PR https://github.com/stoplightio/spectral/pull/2658 to https://github.com/stoplightio/spectral.
https://github.com/stoplightio/spectral/pull/2658 is merged. I hope this will help with @sam0r040's issue.
The second step in fixing this bug is merging of PR https://github.com/asyncapi/parser-js/pull/1042
The third and final step in fixing this bug is the merging of PR https://github.com/asyncapi/studio/pull/1124.