Skip to content

Commit f46a56f

Browse files
authored
Fix various schema bugs and cli.js improvements (#4603)
* Fix various schema bugs and `cli.js` improvements * Add more checks and tweak `CONTRIBUTING.md`
1 parent 6b76e49 commit f46a56f

26 files changed

+356
-238
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ body:
3232
required: true
3333
- type: textarea
3434
attributes:
35-
label: YAML or JSON file that does not work.
35+
label: JSON, YAML, or TOML file that does not work.
3636
placeholder: |
3737
This file is used to reproduce the problem.
3838
validations:
File renamed without changes.

.github/workflows/lint.yml renamed to .github/workflows/pre-commit-checks.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: 'Maintenance: Lint'
1+
name: 'Maintenance: precommit checks'
22

33
on: [push, pull_request]
44

55
jobs:
6-
lint-editorconfig:
6+
pre-commit:
77
runs-on: ubuntu-latest
8-
name: Lint for editorconfig violations
8+
name: Run pre-commit checks
99
steps:
1010
- name: Checkout the repository
1111
uses: actions/checkout@v4
File renamed without changes.

.github/workflows/nodejs.yml renamed to .github/workflows/validate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: 'Validate JSON Schemas'
33
on: [push, pull_request]
44

55
jobs:
6-
check:
6+
validate:
77
runs-on: ubuntu-latest
88
timeout-minutes: 10
99

CONTRIBUTING.md

+25-34
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ There are various ways you can contribute:
6161
- Add positive/negative tests
6262
- Refactor to pass under strict mode
6363

64-
Most people want to add a new schema. For steps on how to do this, read the [How to add a JSON Schema that's hosted in this repository](#how-to-add-a-json-schema-thats-hosted-in-this-repository) section below.
64+
Most people want to add a new schema. For steps on how to do this, read the [How to add a JSON Schema that's hosted in this repository](#how-to-add-a-json-schema-thats-hosted-in-this-repository) section below. Find instructions for other tasks under the [How To](#how-to) section.
6565

6666
If you want to contribute, but not sure what needs fixing, see the [help wanted](https://github.com/SchemaStore/schemastore/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) and [good first issue](https://github.com/SchemaStore/schemastore/issues?q=is%3Aopen+label%3A%22good+first+issue%22+sort%3Aupdated-desc) labels on GitHub.
6767

6868
## Overview
6969

70-
Schema files are located in `src/schemas/json`. Each schema file has a corresponding entry in the [Schema Catalog](src/api/json/catalog.json). Each catalog entry has a `fileMatch` field. IDEs use this field to know which files the schema should be used for (in autocompletion).
70+
Schema files are located in `src/schemas/json`. Each schema file has a corresponding entry in the [Schema Catalog](src/api/json/catalog.json). Each catalog entry has a `fileMatch` field. IDEs and language servers use this field to know which files the schema should be used for (in autocompletion).
7171

7272
Some schema files have associated positive and negative tests, located at `src/test` and `src/negative_test`, respectively. These tests may be in JSON, YAML, or TOML format.
7373

@@ -91,9 +91,24 @@ The goal of JSON Schemas in this repository is to correctly validate schemas tha
9191

9292
### Best practices
9393

94-
✔️ **Use** the most recent JSON Schema version (specified by `$schema`) that's widely supported by editors and IDEs. Currently, the best supported version is `draft-07`. Later versions of JSON Schema are not recommended for use in SchemaStore until editor/IDE support improves for those versions.
94+
- We recommend using the `draft-07` JSON schema version. Later versions of JSON Schema are not yet recommended for use in SchemaStore until IDE and language support improves for those versions.
9595

96-
✔️ **Use** [`base.json`][base] schema for `draft-07` and [`base-04.json`][base-04] for `draft-04` with some common types for all schemas.
96+
**Don't forget** add test files.
97+
98+
### Useful Conventions
99+
100+
- Consider using documentation URLs in `"description"` to improve UX. Most schemas use the format `<description>\n<url>`. For example: `"Whether to ignore a theme configuration for the current site\nhttps://jekyllrb.com/docs/configuration/options/#global-configuration"`
101+
- Consider using the [`base.json`][base] schema for `draft-07` or [`base-04.json`][base-04] for `draft-04` to use subschemas that are commonly used.
102+
- When writing `description`, avoid phrases like "there are three possibilities" and "valid values are" in favor of adding the constraints to the schema directly.
103+
- If you choose to use `title`, we recommend formatting it so that object values look like types in programming languages. This includes:
104+
- Omitting leading articles and trailing punctuation
105+
- Beginning it with a lowercase letter
106+
- Using nouns instead of sentences
107+
108+
**Unofficial Strict Mode**
109+
110+
> [!WARNING]
111+
> This "unofficial strict mode" may have bugs or be incomplete.
97112
98113
There is an [unofficial draft-07][draft-07-unofficial-strict] schema that uses JSON Schema to validate your JSON Schema. It checks that:
99114

@@ -102,21 +117,7 @@ There is an [unofficial draft-07][draft-07-unofficial-strict] schema that uses J
102117
- `type` can't be an array, which is intentional, `anyOf`/`oneOf` should be used in this case
103118
- It links to [understanding-json-schema](https://json-schema.org/understanding-json-schema) for each hint/check
104119

105-
To check your schema against that schema, use `node cli.js check-strict --schema-name=<schemaName.json>`.
106-
107-
**Don't forget** add test files.
108-
109-
- Always be consistent across your schema: order properties and describe in the same style.
110-
- Always use `description`, `type`, `additionalProperties`.
111-
- Always set `additionalProperties` to `false` unless documentation permits
112-
additional properties explicitly. That tool the JSON schema is created for
113-
can be changed in the future to allow wrong extra properties.
114-
- Don't end `title`/`description` values with colon.
115-
- Always omit leading articles for `title`-s and trailing punctuation to make
116-
expected object values look more like types in programming languages. Also
117-
start `title`-s with a lowercase letter and try use nouns for titles instead of sentences.
118-
- Always add documentation url to descriptions when available in the following
119-
format: `<description>\n<url>` like `"Whether to ignore a theme configuration for the current site\nhttps://jekyllrb.com/docs/configuration/options/#global-configuration"`.
120+
To check your schema against that schema, use `node cli.js check-strict --schema-name=<schemaName.json>`. Note that this is NOT the same as Ajv strict mode.
120121

121122
[base]: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/base.json
122123
[base-04]: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/base-04.json
@@ -129,13 +130,13 @@ Sometimes, constraints do more harm than good. For example, [cron strings](http:
129130
- false positives are likely (due to their complexity or abundance of implementations)
130131
- its error message is too confusing or not helpful
131132

132-
So, do not add regex patterns for any of the following:
133+
So, we recommend avoiding regex patterns for:
133134

134135
- cron regexes
135136
- string-embedded DSLs
136137
- SSH URLs, HTTPS URLs, and other complex URIs
137138

138-
In addition, be wary when adding exhaustive support to enum-type fields. Often, when applications expand support (thus expanding the set of allowable enums), the schema will become invalid.
139+
In addition, be wary when adding exhaustive support to enum-type fields (without a `"type": "string"` fallback). Often, when applications expand support (thus expanding the set of allowable enums), the schema will become invalid.
139140

140141
#### Undocumented Features
141142

@@ -194,7 +195,7 @@ Note that JSON Schema draft `2019-09` adds support for a `deprecated` field:
194195
}
195196
```
196197

197-
While this would be the best option, most schemas in this repository are `draft-07`. As a result, _Editors and IDEs may not use it_.
198+
While this would be the best option, most schemas in this repository are `draft-07`. As a result, _IDEs and language servers may not use it_.
198199

199200
#### API Compatibility
200201

@@ -368,7 +369,7 @@ To actually run the validation checks, see [How to validate a JSON Schema](#how-
368369

369370
## About `catalog.json`
370371

371-
The `catalog.json` file is generally used by editors and extensions to determine which schemas apply to what files. Specifically:
372+
The `catalog.json` file is generally used by IDEs and language servers to determine which schemas apply to what files. Specifically:
372373

373374
- VSCode ignores this file [see issue](https://github.com/microsoft/vscode/issues/26289)
374375
- [RedHat's YAML language server](#redhat-developeryaml-language-server) uses this file ([see configuration](https://github.com/redhat-developer/vscode-yaml/blob/41e0be736f2d07cdf7489e1c1c591b35b990e096/package.json#L176))
@@ -468,17 +469,7 @@ To fix this, run the formatter manually:
468469
npm run prettier:fix
469470
```
470471

471-
Note this will also format the following files:
472-
473-
```sh
474-
$ git status --short
475-
M src/test/prettierrc/.prettierrc.yml
476-
M src/test/prettierrc/prettierrc.json
477-
```
478-
479-
_Do not_ add those two files; pre-commit.ci seems to have issue with them. (Undo modifications to those files by running `git restore -- 'src/test/prettierrc/*'`)
480-
481-
To run Prettier on scpecific files, run:
472+
To run Prettier on specific files, run:
482473

483474
```console
484475
# Run on a schema file

0 commit comments

Comments
 (0)