|
22 | 22 | - [How to add a `$ref` to a JSON Schema that's self-hosted](#how-to-add-a-ref-to-a-json-schema-thats-self-hosted) |
23 | 23 | - [How to validate a JSON Schema](#how-to-validate-a-json-schema) |
24 | 24 | - [How to ignore validation errors in a JSON Schema](#how-to-ignore-validation-errors-in-a-json-schema) |
| 25 | + - [How to name schemas that are subschemas (`partial-`)](#how-to-name-schemas-that-are-subschemas-partial-) |
25 | 26 |
|
26 | 27 | ## Introduction |
27 | 28 |
|
@@ -377,3 +378,17 @@ To ignore most validation errors, you need to modify `src/schema-validation.json |
377 | 378 | - If a strict error fails, you need to add your JSON Schema to the `ajvNotStrictMode` array |
378 | 379 | - If you are getting "unknown format" or "unknown keyword" errors, you need to add your JSON Schema to the `options` array |
379 | 380 | - If you are using a recent version of the JSON Schema specification, you will need to add your JSON Schema to the `highSchemaVersion` array |
| 381 | + |
| 382 | +### How to name schemas that are subschemas (`partial-`) |
| 383 | + |
| 384 | +Often, it is useful to extract a subschema into its own file. This can make it easier to write tests, find schemas pertaining to a particular project, and logically separate extremely large schemas. The `partial-` prefix makes it easier to for IDEs identify these schemas (and ignore them since they do not correspond to a file. `fileMatch: []` does not cover this case). |
| 385 | + |
| 386 | +A subschema should be extracted to its own file based on the following rules: |
| 387 | + |
| 388 | +- If a schema represents an existing project that could be its own file, then simply use that file for the "subschema". In other places, `$ref` that file where appropriate. |
| 389 | + - For example, [mypy](https://mypy-lang.org) reads configuration from both `mypy.ini` and `pyproject.toml`'s `tool.mypy` key. Because `mypy.ini` is its own file, then name the schema `mypy.json` like you usually would. |
| 390 | + - Same with [Prettier](https://prettier.io). It reads from `.prettierrc.json` (among other files) and `package.json`'s `prettier` key. |
| 391 | +- If the schema cannot be its own file, then extracting the subschema may be an improvement |
| 392 | + - For example, [Poetry](https://python-poetry.org) reads configuration _only_ from `pyproject.toml`'s `tool.poetry` key. Because the Poetry subschema is relatively complex and a large project, it has been extracted to its own file, `partial-poetry.json`. |
| 393 | + |
| 394 | +Use your best judgement; if the project or schema is small, then the drawbacks of extracting the subschema to its own file likely outweigh the benefits. |
0 commit comments