Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix: wrong validation with AsyncAPI v3 in VS Code and JetBrains IDEs #495
fix: wrong validation with AsyncAPI v3 in VS Code and JetBrains IDEs #495
Changes from 6 commits
0396524
8af32be
518e3e0
78ce54d
b5f2139
87a6097
981c80d
212cc82
e8ee4a2
b573b54
62c5193
297e778
dddb3d3
a4c5ef0
acfb26e
469431c
b45e610
52b06c5
d34130d
a9a7d47
eba77ed
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a deep investigation, I concluded this cannot be changed to
anyOf
and should stay asallOf
.The reason is that
anyOf
will try to match with any schema in the array. The problem is that since those schemas areif
, and anif
conditional fails, it is considered an empty schema, which is equivalent totrue
assertion of that element in theanyOf
array.See this example I made by extracting the logic in place and reducing the complexity for test purposes: https://www.jsonschemavalidator.net/s/q0RfvVqb
As you can see, the
if
is failing (doesn't match the schemaFormat), but theanyOf
is resulting in a true assertion. Totally against what we expect.How can we fix then the issue?
Let's read what the JSON Schema validator says:
The issue comes not at this line, but at this other one.
The point is that the keyword
$ref
is both defined in theReference
schema and in theschema
, which is a superset of JSON Schema and it does include the$ref
keyword itself.That's why JSON Schema validation says the schema is matching with more than one schema in this
oneOf
.By changing that
oneOf
toanyOf
, we ensure that by matching with any of those schemas will be considered a valid doc.I spent some time trying to find edge-cases for the change I'm suggesting. For example, what if we change how our Reference Object (
$ref
) look like? Then, it will differ from JSON Schema provided one, and we could set it back then tooneOf
if needed.Btw, this change should be propagated to the
oneOf
in OpenAPI since OpenAPI schema is also a superset of JSON Schema and it includes the$ref
property.Additionally, I investigated a bit if we could get rid of those
if/then
and I believe we could just useallOf
with all the possible cases as schemas right directly, without theif/then
, including the case when theschemaFormat
is just an unknownstring
.But this, is out of the scope of this issue I believe. Just for the record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smoya check out new validation rules. I have removed all
if/then
constructionsPlayground: https://www.jsonschemavalidator.net/s/JmGON4jI
Specification to test: