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

[json] support JSON schema draft-06 #29152

Closed
itowlson opened this issue Jun 21, 2017 · 2 comments
Closed

[json] support JSON schema draft-06 #29152

itowlson opened this issue Jun 21, 2017 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality json JSON support issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@itowlson
Copy link

itowlson commented Jun 21, 2017

JSON Schema draft-06 includes a const keyword to indicate that a property must be a specific value (http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.24). VS Code does not report a problem if the property does not match the value. (It does work if you use an enum with a single value.)


Steps to Reproduce:

  1. See sample repo https://github.com/itowlson/vscode-json-schema-test and load the extension. Note the contents of schema/foo.schema.json.

  2. Run this extension in the Extension Development Host (or create a new extension and add the jsonValidation section and foo.schema.json file from the sample repo).

  3. In the Extension Development Host, open the file test/test.foo.json.

  4. View the "apiVersion" element. Expected: A warning squiggly, and hover message along the lines of "Value is not accepted. Valid value: ''2017-01-01.1.0'" (basing this on the enum message - I'm sure you can word it better). Actual: no warning.

(The "apiVersionWorkaround" element works correctly - I included it only so you could compare the const behaviour to the single-value enum behaviour.)


  • VSCode Version: Code 1.13.1 (379d2ef, 2017-06-14T18:21:47.485Z)
  • OS Version: Windows_NT ia32 10.0.14393
  • Extensions:
Extension Author Version
jshint dbaeumer 0.10.15
vscode-eslint dbaeumer 1.2.11
mdhelper joshbax 0.0.9
@aeschli aeschli changed the title JSON validation does not validate const keyword [json] support const keyword Jun 21, 2017
@aeschli aeschli added json JSON support issues feature-request Request for new features or functionality labels Jun 21, 2017
@aeschli aeschli added this to the Backlog milestone Jun 21, 2017
@lijunle
Copy link
Member

lijunle commented Aug 1, 2017

Here are the supporting JSON schema keywords.

I use the pattern keyword with type:string as a workaround although they are not exact the same function.

Another missing keyword is contains.

@aeschli aeschli modified the milestones: Backlog, October 2017 Oct 11, 2017
@aeschli aeschli changed the title [json] support const keyword [json] support JSON schema draft-06 Oct 12, 2017
aeschli added a commit to microsoft/vscode-json-languageservice that referenced this issue Oct 13, 2017
aeschli added a commit to microsoft/vscode-json-languageservice that referenced this issue Oct 13, 2017
aeschli added a commit to microsoft/vscode-json-languageservice that referenced this issue Oct 13, 2017
aeschli added a commit to microsoft/vscode-json-languageservice that referenced this issue Oct 13, 2017
@aeschli aeschli added the verification-needed Verification of issue is requested label Nov 1, 2017
@aeschli
Copy link
Contributor

aeschli commented Nov 1, 2017

To verify: See http://json-schema.org/draft-06/json-schema-migration-faq.html for additions & changes:

property change --
"exclusiveMinimum"and "exclusiveMaximum" changed from a boolean to a number to be consistent with the principle of keyword independence wherever one of these would be true before, change the value to the corresponding "minimum" or "maximum" value and remove the "minimum"/"maximum"keyword
booleans as schemas allowable anywhere, not just "additionalProperties"and "additionalItems" true is equivalent to {}, false is equivalent to {"not": {}}, but the intent is more clear and implementations can optimize these cases more easily
"propertyNames" added takes a schema which validates the namesof all properties rather than their values
"contains" added array keyword that passes validation if its schema validates at least one array item
"const" added more readible form of a one-element "enum"

draf06test.schema.json

{
    "$schema": "http://json-schema.org/draft-06/schema",
    "type": "object",
    "properties": {
        "n": {
            "type": "number",
            "exclusiveMinimum": 5,
            "exclusiveMaximum": 7
        },
        "p": {
            "type": "object",
            "propertyNames": {
                "pattern": "[1-9]"
            }
        },
        "a": {
            "type": "array",
            "contains": {
                "type": "boolean"
            }
        },
        "foo": {
            "type": "string",
            "const": "bar",
            "description": "It can only be bar"
        }
    }
}

draft06test.json

{
    "$schema": "./draft06test.schema.json",
    "n": 5,
    "p": {
        "1": true,
        "f": false
    },
    "a": [ 1, 2],
    "foo": "bar"
}

@sandy081 sandy081 added the verified Verification succeeded label Nov 1, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality json JSON support issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants