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

draft/2019-09: exclusiveMinimum and exclusiveMaximum must be numbers #71

Open
saman opened this issue Aug 26, 2020 · 12 comments
Open

draft/2019-09: exclusiveMinimum and exclusiveMaximum must be numbers #71

saman opened this issue Aug 26, 2020 · 12 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@saman
Copy link

saman commented Aug 26, 2020

In my workspace, if I put $schema to 2019-09, and set exclusiveMinimum and exclusiveMaximum with a boolean is not throwing any error.

Considering these two examples:

A JSON Schema based on draft-07

{
    "$id": "https://example.com/my-schema",
    "$schema": "https://json-schema.org/draft-07/schema",
    "properties": {
        "test": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true,
            "maximum": 100,
            "exclusiveMaximum": true
        }
    }
}

And a JSON Schema based on lastest version draft 2019-09

{
    "$id": "https://example.com/my-schema",
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "properties": {
        "test": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true,
            "maximum": 100,
            "exclusiveMaximum": true
        }
    }
}

The example with draft 2019-09 is going to be accepted, while the first example with draft-07 throws an error as expected:
Incorrect type. Expected "number".

As I can see in jsonParser.ts is going to accept both number and boolean on 2019-09 which is incorrect while It is showing an expected error on draft-09.
2019-09 draft specefication mention this:

6.2.3. exclusiveMaximum
The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.

6.2.5. exclusiveMinimum
The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.

@KapitanOczywisty
Copy link
Contributor

@saman 2019-09 is not yet supported. Also this is not a problem with exclusiveMinimum, but with properties which is defined with new $recursiveRef property. https://github.com/json-schema-org/json-schema-spec/blob/2019-09/meta/applicator.json#L25

@Trias
Copy link

Trias commented Aug 27, 2020

Not the OP, but is there any 2019-09 support planned?

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Aug 27, 2020

Not the OP, but is there any 2019-09 support planned?

@aeschli ? :)

@aeschli
Copy link
Contributor

aeschli commented Aug 27, 2020

We have microsoft/vscode#98724 as issue to support 2019-09.
It hasn't been requested many times yet, and don't know yet when I will able to tackle it. If anyone wants to help, that would be fantastic.

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Aug 27, 2020

@aeschli I might implement some features, but specification is very unfriendly to non-native speakers.

Btw. shouldn't this be resolveErrors? There is code to warn about 2019-09, but there is no visible warning in vscode.

} else if (id === 'https://json-schema.org/draft/2019-09/schema') {
schemaToResolve.errors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));

@Relequestual
Copy link
Contributor

@aeschli I'm not sure any of the JSON Schema team can help with the actual implementation, but I can sure help with any clarifications if required!

It may be helpful to know there is already an implementation in js (https://github.com/hyperjump-io/json-schema-validator).

The test suite for 2019-09 is still not yet complete... but we're working on it...

@aeschli
Copy link
Contributor

aeschli commented Aug 27, 2020

@KapitanOczywisty Good catch, fixed resolveErrors, now the error will show

@aeschli aeschli changed the title exclusiveMinimum and exclusiveMaximum data types draft/2019-09: exclusiveMinimum and exclusiveMaximum must be numbers Aug 27, 2020
@KapitanOczywisty
Copy link
Contributor

@Relequestual $recursiveRef and $recursiveAnchor are the first to implement since they're breaking completely new schema.
Few questions:

  1. $recursiveAnchor can be only in schema's root?
  2. $recursiveRef always has value of #?
  3. in absence of $recursiveAnchor (or false), is $recursiveRef equal to $ref?

@aeschli aeschli added this to the Backlog milestone Nov 12, 2020
@aeschli aeschli added the feature-request Request for new features or functionality label Nov 12, 2020
@Relequestual
Copy link
Contributor

@Relequestual $recursiveRef and $recursiveAnchor are the first to implement since they're breaking completely new schema.
Few questions:

1. `$recursiveAnchor` can be only in schema's root?

2. `$recursiveRef` always has value of `#`?

3. in absence of `$recursiveAnchor` (or false), is `$recursiveRef` equal to `$ref`?

Yes, Yes, and, Yes.

We recently release JSON Schema draft 2020-12. We've tweaked this to be more useful, but it may be a little harder to understand.

Come by the JSON Schema slack if you have more questions =]

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Dec 17, 2020

I wonder If It wouldn't be better to use ajv instead writing another dedicated implementation. This extension is probably used by vscode internally, but ajv is pretty light and wouldn't be adding much overhead. @aeschli ?

@Relequestual
Copy link
Contributor

It might be, although I assume this code gives a lot more features, such as auto-complete and highlights.
You may get better results out of using the core part (separate repo) from hyperjump, which is the first 2020-12 implementation.

@KapitanOczywisty
Copy link
Contributor

Additional features you have to implement anyway, but might be easier when you're not concerned about schema formats. However validation for incomplete schema might be not handled by ajv, which is a problem.. Just forget that bad idea 😛

Back to topic: With 3x Yes, $recursiveRef should be easy to implement in existing structure, with minor changes. But again 2020-12 have $dynamicRef which seems not that easy, so probably $ref mechanics have to be overhauled which is beyond my capabilities atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants