-
-
Notifications
You must be signed in to change notification settings - Fork 315
Linter #1079
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
Comments
I'll move this elsewhere once an appropriate place exists! 😅 |
Based on w3c/wot-thing-description#1194 it would also be nice to be able to check this as well:
|
Two more:
|
@mitar Not trying to shoot your idea down, but I find this a bit debatable. If I understand the semantics correctly, the "URL" in the "$ref" isn't really a URL. It's more like an identifier. In the most general sense, you could have a resolver that takes that "URL" and resolves it to a schema, which isn't necessarily retrieved via http or https at all. |
I agree. The linting tool should definitely have a way to enable/disable rules to use. |
Lint that all string properties that define a regex pattern are internally consistent and obey this regex pattern in their default / example values. For example, the default and examples in this simple schema are no good! however, they seem to pass in this validator: {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"properties": {
"lowerLettersOnly": {
"pattern": "^[a-z]*$",
"default": "bad_default01",
"examples": [
"imatch",
"i-do-NOT-match01"
]
}
}
} I actually think this should be an invalid schema spec, not just a linting issue, @kze should that be a separate GH issue? |
Covering
This isn't currently possible with stock JSON Schema because we'd have to reference data (the pattern) and apply schema validations against that data. (It is supported with this vocabulary, though.) |
A place now exists 😄. I've added some things from here. |
Is it OK for everyone if we create a Github Project dashboard to co-create and visualize all the rule proposals?
|
We need to do this in the linting repo, https://github.com/json-schema-org/json-schema-linting |
I've commented on that issue. tl;dr - The rules for |
URIs are only identifiers, not locators. Whether |
Uh oh!
There was an error while loading. Please reload this page.
Per @Relequestual's recommendation, I'm creating a ticket about a linter and to collect linting rules that people would want.
When authoring a JSON schema, it is desirable to have a linter to check the strictness, specificity, satisfiability, and descriptiveness of a schema. Maybe Ben envisions the JSON schema workgroup to produce a reference linter implementation?
Anyway, I'll start with a list of linting rules that would be desirable (assuming draft 07):
additionalProperties
explicitly set? Is it set to eitherfalse
or a schema (not justtrue
)?additionalProperties
is defined, ispropertyNames
also defined?required
defined? Are all fields listed inrequired
?properties
,additionalProperties
, andrequired
? E.g. this schema is not satisfiable:foo
is required, but is not defined amongproperties
, yet we also disallow additional properties.additionalProperties
is notfalse
or some fields are missing fromrequired
:minProperties
andmaxProperties
also defined?maxProperties
>= the length ofrequired
?$ref
or$ref
-in-allOf
) and"additionalProperties": false
present together? Usually that's a sign of the author trying to do poor man's inheritance in JSON schema. The"additonalProperties": false
will likely cause an object to not validate against the schema, counter to the user's expectations.multipleOf
minimum
/exclusiveMinimum
andmaximum
/exclusiveMaximum
minimum
andexclusiveMinimum
should not be defined togethermaximum
andexclusiveMaximum
should not be defined togetherminimum
andmaximum
are defined,minimum
should be <=maximum
;minimum
andexclusiveMaximum
are defined,minimum
should be <exclusiveMaximum
;exclusiveMinimum
andmaximum
are defined,exclusiveMinimum
should be <maximum
;exclusiveMinimum
andexclusiveMaximum
are defined:type
is"integer"
:exclusiveMaximum - exclusiveMinimum
should be > 1type
is"number"
:exclusiveMinimum
should be <exclusiveMaximum
format
?minLength
andmaxLength
?minLength
<=maxLength
?items
schemas?items
as a fixed-length array of schemas; oritems
as a single schemaminItems
andmaxItems
defined?minItems
<=maxItems
?uniqueItems
explicitly set? Eithertrue
orfalse
is ok. We just want it to be explicit.title
?description
?$comment
?default
?default
satisfy the schema?examples
?examples
satisfy the schema?Ideally, the linter shall be able to generate output that is machine-parsable, with the appropriate JSON pointer so that the author can choose to silence/ignore certain warnings.
I know there are more ways for a schema to become unsatisfiable. E.g. a string could have a regex pattern that can only be 3 characters long, but the author also specifies
"minLength": 10
. This kind of satisfiability violation is too complex to check. I don't expect any linter to be able to check for that.The text was updated successfully, but these errors were encountered: