Behaviour SwRS-MDOKFSTUDIO-FMSCHEMA-023
Schemas in YAML, JSON or JSON5 with relative references compile or report a row
When a schema file is written in YAML, JSON or JSON5, the extension SHALL load it, stripping line and block comments outside strings from JSON and JSON5 files and inlining its relative `$ref` references to other files of the schema folder, and showing a row of the table for a schema it cannot parse or compile.
Step 2 of path 1 in StRS-MDOKFSTUDIO-FMSCHEMA-006: from “A schema file is found” to “The schema is loaded”.
Scenarios 9
The situations the tests check; open one to read it.
nominalJSON5 with comments
Givena Note.schema.json5 file with a line comment, a block comment and one declared string property
Whena document of type Note is analysed
Thenthe schema loads and the property is listed with its text type
nominalExtension fallback of a relative reference
Givena schema with allOf holding a node `$ref: base.schema` and a folder with base.schema.yml declaring an id string property
Whenthe document is analysed
Thenthe resolved schema declares the id property and no $ref remains in it
a node that is exactly a relative `$ref` is replaced by the content of the file, trying the name as written then `.json`, `.json5`, `.yaml` and `.yml`
a node that is exactly a relative `$ref` is replaced by the content of the file, trying the name as written then `.json`, `.json5`, `.yaml` and `.yml`
boundaryOther forms of a relative reference
| Input | Outcome |
|---|---|
| two schema files that refer to each other | the first inlined copy is kept, the inner reference stays as a reference to the schema root and the analysis ends |
| `$ref: base.schema.yaml#defs` and a base.schema.yaml whose key defs holds a number schema | the node is replaced by the content of the defs key |
| two properties a and b that both refer to base.schema.yaml, which is not part of a cycle | a is replaced by the file content and b becomes a reference to the schema root |
| `$ref: nope.yaml` whose file does not exist | the node becomes a reference to the schema root (the fragment alone is kept when the reference has one) |
refusalStandard JSON pointer fragment
Givena node `$ref: base.schema.yaml#/defs/s` for the same file
Whenthe document is analysed
Thenthe property that holds the reference is left without a schema, the schema does not compile and the red row "Schema validation failed to run: schema is invalid: ..." is shown
refusalSchema that cannot be parsed
| Input | Outcome |
|---|---|
| a Note.schema.json5 file that is not valid JSON after comments are stripped | the table is generic and one warning row starts with "Schema could not be parsed: {error}", with a warning badge |
| a Note.schema.json5 file with a trailing comma after the last property | the schema cannot be parsed and the warning row "Schema could not be parsed: {error}" is shown |
refusalYAML syntax error
Givena Note.schema.yaml file holding the line `type: [a`
Whena document of type Note is analysed
Thenno "Schema could not be parsed" row appears; the partly parsed content is used and here the validator rejects it with the "Schema validation failed to run" row
boundaryEmpty YAML schema
Givena Note.schema.yaml file that is empty or holds only comments
Whena document of type Note is analysed
Thenthe type stays without schema: the table is generic, one informational row reads "schema file 'Note.schema.yaml' is empty" (the wording of okf-schema), the summary is 0 errors, 0 warnings, 1 info and the analysis does not throw
refusalSchema that cannot be compiled
Givena schema declaring a property with `type: nonsense`
Whena document of type Note is analysed
Thenone red alert row reads "Schema validation failed to run: schema is invalid: ..." and the badge reads 1 error
the declared fields are still listed in schema order, with their documentation
the declared fields are still listed in schema order, with their documentation
boundaryCompile failure in a narrow preview
Giventhe same table in a 460 px preview with the Description column hidden
Whenthe preview is rendered
Thenthe row spans two columns and no text overflows
Implemented in 2
Tested by 5
Known limits (8)
- the reference cycle scenario has no test.
- JSON5 support is minimal: trailing commas and unquoted keys fail as a schema that cannot be parsed.
- a reference such as `../../x.yaml` is read even when it leaves the schema folder (only a trusted workspace reaches this code).
- a file reference with a standard JSON-pointer fragment such as `base.schema.yaml#/defs/s` leaves the property that holds it without a schema (the pointer is split with an empty first segment, so the lookup returns undefined); the property stays listed, but Ajv refuses the whole schema ("schema is invalid: data/properties/a must be object,boolean"), the table shows the red row "Schema validation failed to run: ..." and every validation is lost; a fragment without the leading slash such as `base.schema.yaml#defs` selects the key.
- the set of inlined files is shared by the whole resolution and never emptied, so a second reference to a file that is already inlined (no cycle) becomes a reference to the schema root and the field is validated against the whole schema.
- a missing target becomes a reference to the schema root, not an unresolved reference.
- a reference with a sibling keyword next to `$ref` is not inlined.
- a YAML syntax error is not reported: the parse errors of the YAML document are never checked, so the partly parsed schema is applied silently.
Replaces
SwRS-MDOKFSTUDIO-FMSCHEMA-024Relative schema references are inlined from the schema folder superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-023 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-025A schema that cannot be parsed gives a warning row superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-023 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-026A schema that cannot be compiled gives a red row superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-023 Markdown file