Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-FMSCHEMA-019

A typed document finds its schema in the nearest schema folder

When a document's frontmatter has a string `type`, the extension SHALL look for the schema folder by walking up from the document's folder to the workspace folder root and use the first `_schema` folder, or `_schemas` when a level has no `_schema`, pick in it the file `{type}.schema.yaml`, `.yml`, `.json` or `.json5` whose stem equals the type ignoring case, and look up no schema when the workspace is not trusted or the document is not inside a workspace folder.

Step 1 of path 1 in StRS-MDOKFSTUDIO-FMSCHEMA-006: from “The frontmatter has a string `type`” to “A schema file is found”.

Scenarios 7

The situations the tests check; open one to read it.

nominalNearest folder wins
Givena workspace with `_schema` at its root and `_schema` in the sub-folder docs, and a document in docs/guide
Whenthe document is analysed
Thenthe schema folder is docs/_schema
nominalThe file is chosen by the type name
InputOutcome
A schema folder with Note.schema.yaml and a document of type noteNote.schema.yaml is used as the schema
A schema folder with note.schema.json, note.schema.yml and note.schema.yamlnote.schema.yaml is used and the other two files are ignored (preference `.yaml`, then `.yml`, `.json`, `.json5`)
boundaryFolder and file matching
InputOutcome
A level that holds both `_schema` and `_schemas``_schema` is preferred
A `_schema` at the workspace folder root itselfIt is found; the stop directory is included
No workspace rootThe walk runs up to the file-system root
A file named Note.SCHEMA.YAML and a document of type noteIt matches; the stem and the `.schema` suffix are compared in lower case
A file that does not end in `.schema` plus an accepted extensionIt never matches
refusalNo schema folder
Givena workspace with no `_schema` or `_schemas` folder above the document
Whenthe document is analysed with a type
Thenthe generic table is shown and no info row appears
refusalNo file for the type
Givena schema folder holding only other.schema.yaml and a document of type Note
Whenthe preview is rendered
the file Note.schema.yaml is added to the folder and the document is analysed again
Thenthe table is generic, one info row reads No schema found for type "Note" in _schema/. and the badge reads ℹ 1
the info row is gone and the schema table is shown
refusalNo lookup in Restricted Mode or for a standalone file
InputOutcome
A schema exists for the type, the workspace is in Restricted Mode and the document has `type: Note`No schema is looked up and no field is editable; the generic table shows the info row "Schema validation requires a trusted workspace; showing generic frontmatter." and an info badge
A document without a type in Restricted ModeNo info row is shown
A Markdown file opened outside every workspace folder with a typed frontmatterNo schema is read
boundaryThe schema folder listing is kept while the folder is unchanged
Givena schema folder listed in an earlier render
a schema folder whose modification time is less than 2 seconds old when it is listed
Whenthe document is rendered again, first with the folder unchanged and then after a schema file was added or the folder removed
a schema file is added within the same clock step (the folder's times do not move) and the document is rendered again
Thenthe unchanged folder is not listed again, an added file is found, and a removed folder lists nothing
the folder is listed again and the added file is found

Implemented in 2

Tested by 3

Known limits (2)

Replaces

SwRS-MDOKFSTUDIO-FMSCHEMA-020The schema file is chosen by the type name superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-019 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-021A missing schema file is reported as an info row superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-019 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-022Schema lookup is off in Restricted Mode and for standalone files superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-019 Markdown file
SwRS-MDOKFSTUDIO-FMSCHEMA-077The no-lookup info row appears only for typed documents superseded superseded by SwRS-MDOKFSTUDIO-FMSCHEMA-019 Markdown file