Comments (6)
Use anyOf
instead of oneOf
in your schema can solve this if I understand correctly.
from vscode-json-languageservice.
Use
anyOf
instead ofoneOf
in your schema can solve this if I understand correctly.
good point.
based on http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1.2
9.2.1.2. anyOf
This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against at least one schema defined by this keyword's value. Note that when annotations are being collected, all subschemas MUST be examined so that annotations are collected from each subschema that validates successfully.
9.2.1.3. oneOf
This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against exactly one schema defined by this keyword's value.
so the fact that a validation error is provided respect the specification. What would be interesting would be to improve the error message to point to the specification maybe?
nota: this will surely break a lot of other softwares that rely on this message: https://github.com/search?q=%22Matches+multiple+schemas+when+only+one+must+validate.%22&type=Code
from vscode-json-languageservice.
Do you have a suggestion on how the message should be improved? IMO the current message is correct.
from vscode-json-languageservice.
the current message is correct.
yes, it is correct. Unfortunately, i wasn't able to understand what was wrong and how to fix that. Given the large amount of people asking the same questions on StackOverflow, i think it will be good to find a way to drive more newbies like me.
Do you have a suggestion on how the message should be improved?
Matches multiple schemas when only one must validate. See json schema specification for oneOf http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1.3
The json schema <xxx> is requiring a single schema match as it is using the oneOf constraint. It is matching several schemas. See also json schema specification for oneOf http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1.3
The json schema <xxx> is requiring a single schema match as it is using the oneOf constraint. It is matching several schemas: <schema-1>, <schema-2>, <schema-3>. See also json schema specification for oneOf http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1.3
from vscode-json-languageservice.
I think the problem is that an end user sees the message, but the user doesn't care about schemas. The user probably wants a message like Object can not have property 'x' as well as 'y'.
.
from vscode-json-languageservice.
Another problem is that there is no way to know which schemas are possible without debugging the service.
Both for an end user and for a schema developer, it should specify something like Matches multiple schemas (Type2, Type5) when only one must validate.
, and then both can fix the problem.
The problem is that schemas don't necessarily have names, unless they're a $ref
, so maybe showing the position in the schema file of the matches will do.
Yes the user doesn't care about schemas, but the user also wants to know what the problem is to work around it and maybe report it.
from vscode-json-languageservice.
Related Issues (20)
- Intellisense recommends invalid schema uris for JSON Schema drafts HOT 2
- Unexpected token after updating to 5.3.5 HOT 1
- Validation of uuid format not working
- doHover seems to use the unresolved schema
- Package exports are problematic HOT 2
- insertFinalNewline should default to true
- anyOf error messaging is broken
- code completion breaks when anyOf defines `required` properties. HOT 2
- Regression: Problems loading reference schemaservice
- How to: $ref to external schemas in VSC
- Intellisense is missing JSON Schema versions 2019-09, 2020-12 HOT 3
- Support `title` schema property in completion items
- JSON Schema meta-schemas should not be downloaded
- Validation of uri-reference format does not seem to work well
- "time" format seems to be incorrectly excluding "00:00:00" HOT 1
- `getInfoContribution` is not composable HOT 1
- `$id` still not supported HOT 2
- Support fetching schemas from github URLs HOT 2
- Add support to declare a Json Schema as Deprecated HOT 2
- JSON schema validation does not work for array items when in a combined schema HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-json-languageservice.