Markdown OKF-Schema Studio

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`
boundaryOther forms of a relative reference
InputOutcome
two schema files that refer to each otherthe 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 schemathe 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 cyclea is replaced by the file content and b becomes a reference to the schema root
`$ref: nope.yaml` whose file does not existthe 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
InputOutcome
a Note.schema.json5 file that is not valid JSON after comments are strippedthe 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 propertythe 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
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)

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