Replies: 1 comment 6 replies
-
Thanks for suggesting and also for trying to assess the consequences it would impose. I agree that it would be great to have validation for As you already stated, we'd need to add the A more scalable approach might be to tell MkDocs to print the configuration that it used for building the project, similar to what Thus, for the reasons stated, we're currently not considering going to add |
Beta Was this translation helpful? Give feedback.
-
Currently, properly configured VS Code recognizes custom YAML tags like
!ENV
inmkdocs.yml
, e.g.but JSON Schema validation fails with an error like this:
That's because the subschema for the
site_url
property declares a"type": "string"
value type:mkdocs-material/docs/schema.json
Lines 17 to 21 in c7f927b
IMO, the DX would be better if
!ENV
tags did not fail validation.I've done some research on how, e.g., GitLab CI is handling the
!reference
tag, but custom YAML tags are invisible to JSON Schema validation and, thus, the best we could do is extend the subschema according to the value type after the tag (see, e.g., the addition of!reference
inrules
).Unfortunately, the
!ENV
tag supports several formatswhich may be ambiguous with hardcoded values in some cases, e.g.
!ENV SOME_VARIABLE
resolves as the string"SOME_VARIABLE"
when passed to the JSON Schema validation. For this reason, it might make sense to extend the schema only for a subset of the possible formats, e.g. only forsince arrays are typically improper values of properties where environment variables are used.
This is what the schema extension for the
site_url
property indocs/schema.json
might look likewith the following new definitions:
The
!ENV
tag also supports an arbitrary number of fallback environment variable names when an explicit default value is provided. Declaring this general pattern isn't possible with JSON Schema to the best of my knowledge (vice versa would be possible throughadditionalItems
1, but that's not what we need 🤷), but we could provide a subschema for a few fallback variables (e.g. 2 in the example above) through tuple validation.Adding support for the
!ENV
tag would introduce quite a bit of noise across the schema files because it can be used in many places. But it would reduce (or even avoid) false errors in IDEs like VS Code, which are a little annoying TBH.WDYT?
Footnotes
A variadic tuple
[number, ...string[]]
can be expressed with JSON Schema like this:Credits to https://github.com/ajv-validator/ajv/issues/1417#issuecomment-770444277 for the inspiration. 🙇
But we'd need something similar to
[string, ...string[], (string | number | boolean | null)]
. 😞 ↩Beta Was this translation helpful? Give feedback.
All reactions