Open joshcorr opened 3 months ago
@joshcorr, the implication in the example document that the schema
keyword isn't required is a mistake on my part. I originally created that example to show how users and authors could edit the data files with IntelliSense and validation provided by the JSON Schemas. I'll update that example shortly to be more correct, I can see how the missing key implies that it's not required.
I did some testing, and the following definition is discoverable and functional, but fails our schema validation:
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.vscode.json
type: Example/Foo
version: 0.1.0
description: An example resource to manage the foo application.
tags:
- foo
get:
executable: foo
args: [get]
input: stdin
set:
executable: foo
input: stdin
preTest: false
return: state
schema:
!command
executable: foo
args: [schema]
Note that for DSC to correctly parse the data from YAML, you have to use the !<tag>
syntax, whereas in JSON you embed the data by the <tag>
keyword - in this case, command
:
{
// ... rest of the manifest
"schema": {
"command": { "executable": "foo", "args": ["schema"] }
}
}
# ... rest of the manifest
schema:
!command
executable: foo
args: [schema]
This is non-intuitive, and difficult to represent with a shared schema (and VS Code will complain that !command
, !url
, and !embedded
are unknown tags).
I believe the fix is to use the serde_yaml::with::singleton_map
customization - the example seem to show the behavior we want.
Prerequisites
Steps to reproduce
In PR #311 support for definitions of resources in YAML was added. However, this does not appear to be working as expected for the schema portion of the definition.
Using a working json schema for a resource (see below), I run y2j to convert it to yaml (also seen below), but the resource is not discovered when
dsc resource list
is executed. If I remove theschema:
section at the end of the yaml file (as this example suggests is not necessary) the resource is discovered but does not execute as the schema is missing from the resource. As I am using the yaml language server validation, any modification to theschema
section to support a YAML tag does not appear valid.working Json resource definition
non discoverable yaml resource definition
discoverable but non-working yaml resource definition
Expected behavior
when executing the resource (that may be discovered)
Actual behavior
when executing the resource (that may be discovered)
Error details
No response
Environment data
Version
dsc 3.0.0-alpha.5
Visuals
No response