Support the `default` JSON Schema keyword
See original GitHub issueWould be nice to be able to specify default values for the rule options in the schema.
See: https://github.com/epoberezkin/ajv#assigning-defaults
I think all you have to do is to set the useDefaults: true
option in https://github.com/eslint/eslint/blob/2af94466fe8f87058fad4bd168958d2a7612a79d/lib/util/ajv.js#L18-L23
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Generic keywords — Understanding JSON Schema 2020-12 ...
The default keyword specifies a default value. This value is not used to fill in missing values during the validation process. Non-validation tools...
Read more >Default value | Opis JSON Schema
You can specify a default value for an item using the default keyword. When a data doesn't have a corresponding value, the value...
Read more >Supported JSON Schema Keywords - Swagger
default – the default value must conform to the specified schema. allOf – the subschemas must be OpenAPI schemas and not standard JSON...
Read more >How to specify defaults conditionally with JSON Schema
The default key word in JSON Schema is an annotation key word. Annotation key words are used to denote information, however they have...
Read more >Generic Keywords - JSON Schema
First, the "$schema" keyword specifies that the current schema follows the specification of the version 3 of JSON Schema. We can provide different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue was accepted in the 2018/09/13 TSC meeting.
(Edit: Also, I noted that ajv’s validate method does mutate the argument passed in once
useDefaults: true
is enabled. So we’ll want to make sure we’re defensively cloning user options or otherwise avoiding problems as best we can)TSC Summary:
JSON Schema supports a “default” keyword which allows schema authors to specify default values for optional properties in an object schema (among other cases). By allowing schemas to have defaults (a 1-line change in the ajv wrapper code), both core rules and custom rules could have default values in schemas.
Additionally (although maybe as a separate proposal), we could write some generic code when creating rule instances which would hydrate default values for any rule options not provided by the user, which would allow us to remove some code in all rules related to option defaults. There shouldn’t be any impact to users because the default keyword only has its semantic meaning as a keyword outside of property lists (i.e., rules with a “default” named option should not be affected).
TSC Question: Should we enable use of “default” keyword in rule schemas?