Comments (9)
It shows if there's no value at all, but as soon as there's a value, the second variant is gone.
Sorry, need to be fixed in code.
from vscode-json-languageservice.
Because of the unfulfilled "required": [ "type", "prop1.2"]
, the first variant gets more weight and is preferred.
from vscode-json-languageservice.
Thanks for the explanation. I wouldn't mind the sorting order depending on the preference determined by the number of missing required properties, but the fact that the "component1.2" suggestion does not appear at all effectively "hides" this variant from the user. Is there any workaround (apart from changing the schema) I could use to have both variants present in the autocomplete list?
from vscode-json-languageservice.
All right, good to know. Looking forward to the fix then!
from vscode-json-languageservice.
I still have the same problem. Is there still no fix or way to fix this?
from vscode-json-languageservice.
One workaround I've found is to add an explicit list of the allowed property (the type
property in my example) values to the polymorphic oneOf
definition:
"component1": {
// workaround start
"properties": {
"type": {
"type": "String",
"enum": [
"component1.1",
"component1.2"
]
}
},
"required": [ "type" ],
// workaround end
"oneOf": [
{
"$ref": "#/definitions/component1.1"
},
{
"$ref": "#/definitions/component1.2"
}
]
}
The complete working Monaco playground example with workaround
var jsonCode = `{
"component": {
"type": ""
}
}`;
var modelUri = monaco.Uri.parse("a://b/foo.json"); // a made up unique URI for our model
var model = monaco.editor.createModel(jsonCode, "json", modelUri);
// configure the JSON language support with schemas and schema associations
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [{
uri: "http://myserver/foo-schema.json", // id of the first schema
fileMatch: [modelUri.toString()], // associate with our model
schema: {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"component1.1": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"component1.1"
]
},
"prop1.1": {
"type": "integer"
}
},
"required": [
"type"
]
},
"component1.2": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"component1.2"
]
},
"prop1.2": {
"type": "integer"
}
},
"required": [
"type",
"prop1.2"
]
},
"component1": {
"properties": {
"type": {
"type": "String",
"enum": [
"component1.1",
"component1.2"
]
}
},
"required": [ "type" ],
"oneOf": [
{
"$ref": "#/definitions/component1.1"
},
{
"$ref": "#/definitions/component1.2"
}
]
}
},
"properties": {
"component": {
"$ref": "#/definitions/component1"
}
}
}
}]
});
monaco.editor.create(document.getElementById("container"), {
model: model
});
The cleanest solution is probably to write a piece of JavaScript that would patch the schema at runtime, just before feeding the schema to Monaco.
from vscode-json-languageservice.
Similar problem but not with enums:
Schema:
{
"oneOf": [
{
"properties": {
"action": { "type": "string", "pattern": "random" },
"value": { "type": "integer" }
},
"required": ["value"]
},
{
"properties": {
"action": { "type": "string", "pattern": "argInteger" },
"arg": { "type": "integer", "description": "integer" }
},
"required": ["arg"]
},
{
"properties": {
"action": { "type": "string", "pattern": "argString" },
"arg": { "type": "string", "description": "string" }
},
"required": ["arg"]
}
]
}
Document:
{
"action": "argString",
}
Triggering completions under the action
property gives only the arg
or argInteger
which autocompletes to "arg": 0
, instead of "arg": ""
which is to be expected.
This is because of the required
s that make the oneOf
not match anything, but the arg
of argInteger
hides the arg
of argString
since they share a name.
from vscode-json-languageservice.
Any updates on this?
from vscode-json-languageservice.
@NotWearingPants resurrecting from the dead.. :)
The oneOf
defined is invalid because you cannot validate the same properties with different type
definitions in a oneOf
.
You would need to define it with a nested oneOf
of type
, or you can use the type
array declaration
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"thing": {
"oneOf": [
{
"properties": {
"action": {
"type": "string",
"pattern": "random"
},
"value": {
"type": "integer"
}
},
"required": [
"value"
]
},
{
"properties": {
"action": {
"type": "string",
"pattern": "argInteger"
},
"arg": {
"oneOf": [
{
"type": "integer"
},
{
"type": "string"
}
]
}
},
"required": [
"arg"
]
}
]
}
}
}
OR type
array
{
"properties": {
"action": {
"type": "string",
"pattern": "argInteger"
},
"arg": {
"type": ["integer", "string"]
}
},
"required": [
"arg"
]
}
from vscode-json-languageservice.
Related Issues (20)
- Assigning $ref to a path that has a pound sign throws an error HOT 1
- Request textDocument/documentSymbol failed. - Cannot read properties of undefined (reading 'range')
- Make JSONSchemaService an API
- defaultSnippets not showing following v5.3.0 HOT 2
- 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
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.