Problems loading reference while authoring resource manifest
Prerequisites
- [x] Write a descriptive title.
- [x] Make sure you are able to repro it on the latest version
- [x] Search the existing issues.
Summary
I am experiencing issues while authoring a resource manifest. Whenever defining the URL shortener: https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json, the manifest.export.json file cannot be loaded.
Changing this to: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/bundled/resource/manifest.json helps me with the IntelliSense features in VSCode.
Steps to reproduce
- Create a
test.dsc.resource.jsonfile - Add
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json"
The warning appears.
Expected behavior
All file references are loaded.
Actual behavior
Not all file references are loaded, breaking some IntelliSense features.
Error details
Environment data
Name Value
---- -----
PSVersion 7.4.7
PSEdition Core
GitCommitId 7.4.7
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Version
3.0.2
Visuals
No response
I did a little investigation and I think I understand the problem.
Essentially, this relates back to the not-fully-implemented support in VS Code for draft 2020-12 - in particular, VS Code doesn't understand canonically bundled schemas. If you have this schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/resource/manifest.json",
"type": "object",
"properties": {
"foo": { "$ref": "$defs/foo" },
"foobar": { "$ref": "$defs/foo/bar" },
"baz": { "$ref": "https://contoso.com/schemas/examples/baz.json" }
},
"$defs": {
"foo": {
"type": "string",
"bar": { "type": "boolean" }
},
"foo/bar": { "type": "integer" },
"https://contoso.com/schemas/examples/baz.json": { "type": "array" }
}
}
When you create a new JSON document using that schema, foo will be of type string, foobar will be of type boolean, and baz won't be resolved (because that schema doesn't exist).
The enhanced authoring schemas do fully work (as far as I can tell in my own testing) for VS Code. You can also use the non-bundled canonical schema, like this:
{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/resource/manifest.json"
// your manifest
}
Further, it looks like VS Code doesn't adjust the canonical URI when using a redirected schema ID - instead of following the redirects from https://aka.ms/dsc/schemas/v3/resource/manifest.json, seeing the actual $id as https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/resource/manifest.json, and then resolving site-relative references properly (relative to the $id in the schema, not the URI specified in your document):
{
"$id": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/resource/manifest.json",
// ellided
"schema": {
"$ref": "/PowerShell/DSC/main/schemas/v3/resource/manifest.schema.json"
}
}
VS Code looks for aka.ms/PowerShell/DSC/main/schemas/v3/resource/manifest.schema.json, which doesn't exist.
I think the "fix" here unfortunately is going to be to document always using the enhanced authoring schemas with VS Code, not the canonical schemas (bundled or otherwise).