Skip to content

Commit 958f67c

Browse files
(SCHEMA) Add stdout schemas for resource operation commands
Prior to this change, the instructions and information about how resources should return data to DSC for any given operation was somewhat vague and not always helpful. This change defines a new set of schemas for the various operations, so resource authors can review their implementations and validate them against these schemas.
1 parent b1b4263 commit 958f67c

File tree

10 files changed

+585
-0
lines changed

10 files changed

+585
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/get.yaml
4+
5+
title: Delete resource operation stdout
6+
description: >-
7+
DSC does not expect the **Delete** operation for a resource to return any JSON to stdout.
8+
markdownDescription: | # VS Code only
9+
***
10+
[_Online Documentation_][00]
11+
***
12+
13+
DSC does not expect the **Delete** operation for a resource to return any JSON to stdout.
14+
15+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/delete?<DOCS_VERSION_PIN>
16+
17+
type: 'null'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/export.yaml
4+
5+
title: Export resource operation stdout
6+
description: >-
7+
Represents the actual state of a resource instance in DSC. DSC expects every JSON Line emitted to
8+
stdout for the **Export** operation to adhere to this schema.
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][00]
12+
***
13+
14+
Represents the actual state of a resource instance in DSC. DSC expects every JSON Line emitted to
15+
stdout for the **Export** operation to adhere to this schema.
16+
17+
The output must be a JSON object. The object must be a valid representation of an instance of the
18+
resource.
19+
20+
Command resources define their instance schema with the [schema.command][01] or
21+
[schema.embedded][02] fields in their resource manifest. If a command resource returns JSON that
22+
is invalid against the resource instance schema, DSC raises an error.
23+
24+
Adapted resource instances are validated by their adapter when the adapter invokes them.
25+
26+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/export?<DOCS_VERSION_PIN>
27+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/command?<DOCS_VERSION_PIN>
28+
[02]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/embedded?<DOCS_VERSION_PIN>
29+
30+
type: object

schemas/src/resource/stdout/get.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/get.yaml
4+
5+
title: Get resource operation stdout
6+
description: >-
7+
Represents the actual state of a resource instance in DSC. DSC expects the JSON Line emitted to
8+
stdout for the **Get** operation to adhere to this schema.
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][00]
12+
***
13+
14+
Represents the actual state of a resource instance in DSC. DSC expects the JSON Line emitted to
15+
stdout for the **Get** operation to adhere to this schema.
16+
17+
The output must be a JSON object. The object must be a valid representation of an instance of the
18+
resource.
19+
20+
Command resources define their instance schema with the [schema.command][01] or
21+
[schema.embedded][02] fields in their resource manifest. If a command resource returns JSON that
22+
is invalid against the resource instance schema, DSC raises an error.
23+
24+
Adapted resource instances are validated by their adapter when the adapter invokes them.
25+
26+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/get?<DOCS_VERSION_PIN>
27+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/command?<DOCS_VERSION_PIN>
28+
[02]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/embedded?<DOCS_VERSION_PIN>
29+
30+
type: object

schemas/src/resource/stdout/list.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/list.yaml
4+
5+
title: List resource operation stdout
6+
description: >-
7+
Defines the representation of an adapted resource in DSC. DSC expects every JSON Line emitted to
8+
stdout for the **List** operation to adhere to this schema.
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][00]
12+
***
13+
14+
Defines the representation of an adapted resource in DSC. DSC expects every JSON Line emitted to
15+
stdout for the **List** operation to adhere to this schema.
16+
17+
DSC includes the following adapter resources:
18+
19+
- `Microsoft.DSC/PowerShell` run PowerShell and enables you to use PowerShell DSC (PSDSC)
20+
resources implemented as PowerShell classes in DSC.
21+
- `Microsoft.Windows/WindowsPowerShell` runs Windows PowerShell and enables you to use any
22+
available PSDSC resources in DSC. This adapter is only available when you install DSC on
23+
Windows.
24+
- `Microsoft.Windows/WMI` enables you to use WMI classes as resources in DSC. This adapter is
25+
only available when you install DSC on Windows.
26+
27+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/list?<DOCS_VERSION_PIN>
28+
29+
type: object
30+
required:
31+
- type
32+
- kind
33+
- version
34+
- capabilities
35+
- path
36+
- directory
37+
- implementedAs
38+
- properties
39+
- requireAdapter
40+
properties:
41+
type:
42+
$ref: /<PREFIX>/<VERSION>/definitions/resourceType.yaml
43+
kind:
44+
$ref: /<PREFIX>/<VERSION>/definitions/resourceKind.yaml
45+
version:
46+
$ref: /<PREFIX>/<VERSION>/definitions/semver.yaml
47+
capabilities:
48+
$ref: /<PREFIX>/<VERSION>/definitions/resourceCapabilities.yaml
49+
path:
50+
title: Path
51+
description: >-
52+
Indicates the path to the adapted resource on the file system.
53+
type: string
54+
directory:
55+
title: Directory
56+
description: >-
57+
Indicates the path to the folder containing the adapted resource on the file system.
58+
implementedAs:
59+
title: Custom implementation name
60+
description: >-
61+
Indicates that the adapted resource uses a custom implementation. The name can be used to
62+
distinguish between different implementations for the adapted resources.
63+
type: string
64+
author:
65+
title: Author
66+
description: >-
67+
Indicates the name of the person or organization that developed and maintains the adapted
68+
Resource.
69+
type:
70+
- string
71+
- 'null'
72+
pattern: ^\w+( \w+)*
73+
properties:
74+
title: Properties
75+
description: >-
76+
Defines the adapted resource's property names.
77+
type: array
78+
items:
79+
type: string
80+
pattern: ^\w+$
81+
requireAdapter:
82+
title: Required adapter
83+
description: >-
84+
Defines the fully qualified type name of the adapter that the adapted resource depends on. An
85+
adapter should always set this value to its own fully qualified resource type name.
86+
$ref: /<PREFIX>/<VERSION>/definitions/resourceType.yaml
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/resolve.yaml
4+
5+
title: Resolve resource operation stdout
6+
description: >-
7+
Defines the representation of a resolved configuration document. DSC expects the JSON Line emitted to
8+
stdout for the **Resolve** operation to adhere to this schema.
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][00]
12+
***
13+
14+
Defines the representation of a resolved configuration document. DSC expects the JSON Line
15+
emitted to stdout for the **Resolve** operation to adhere to this schema.
16+
17+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/resolve?<DOCS_VERSION_PIN>
18+
19+
type: object
20+
required: [configuration]
21+
22+
properties:
23+
configuration:
24+
title: Resolved configuration document
25+
description: >-
26+
Defines the resolved configuration document.
27+
markdownDescription: |-
28+
***
29+
[_Online Documentation_][00]
30+
***
31+
32+
Defines the resolved configuration document. If the configuration document defines any
33+
parameters, values for those parameters may be retrieved from the `parameters` property of
34+
the **Resolve** operation output.
35+
36+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/resolve?<DOCS_VERSION_PIN>#configuration
37+
$ref: /<PREFIX>/<VERSION>/config/document.yaml
38+
parameters:
39+
title: Resolved parameters
40+
description: >-
41+
The `parameters` property defines the set of resolved parameter values for the resolved
42+
configuration document.
43+
markdownDescription: |-
44+
***
45+
[_Online Documentation_][00]
46+
***
47+
48+
The `parameters` property defines the set of resolved parameter values for the resolved
49+
configuration document. If the `parameters` property is omitted from the output for the
50+
**Resolve** operation, DSC doesn't pass any parameters to the resolved configuration
51+
when invoking operations on it.
52+
53+
Each property of this object represents a different resolved parameter. The property name
54+
identifies the name of a parameter. The property value is the resolved value for the
55+
parameter.
56+
57+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/resolve?<DOCS_VERSION_PIN>#parameters
58+
type: object
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/schema.yaml
4+
5+
title: Schema resource command stdout
6+
description: >-
7+
Represents the JSON Schema that validates instances of the resource. DSC expects a resource that
8+
defines the `schema.command` field in its resource manifest to return this value for that
9+
command.
10+
markdownDescription: | # VS Code only
11+
***
12+
[_Online Documentation_][00]
13+
***
14+
15+
Represents the JSON Schema that validates instances of the resource. DSC expects a resource that
16+
defines the [`schema.command`][01] field in its resource manifest to return this value for that
17+
command.
18+
19+
The output must be a JSON object. The object must be a valid JSON Schema. For more information
20+
about what DSC expects for resource instance JSON Schemas, see
21+
[DSC Resource manifest embedded schema reference][02], which describes the expectations in full.
22+
23+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/export?<DOCS_VERSION_PIN>
24+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/command?<DOCS_VERSION_PIN>
25+
[02]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/embedded?<DOCS_VERSION_PIN>
26+
27+
type: object
28+
required:
29+
- $schema
30+
- type
31+
- properties

schemas/src/resource/stdout/set.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/stdout/set.yaml
4+
5+
title: Set resource operation stdout
6+
description: >-
7+
Defines the JSON DSC expects a resource to emit to stdout for the **Set** operation.
8+
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][00]
12+
***
13+
14+
Defines the JSON DSC expects a resource to emit to stdout for the **Set** operation.
15+
16+
DSC expects this output for both actual **Set** operations and **Set** operations in `whatIf`
17+
mode. If the resource has the `whatIf` capability, the output should be the same for both modes.
18+
19+
DSC expects different output from the command resource depending on the definition of
20+
[set.return][01] in the resource manifest:
21+
22+
- If the field isn't defined, DSC doesn't expect the resource to return any JSON to stdout.
23+
Instead, DSC invokes the **Get** operation on the resource after the **Set** operation
24+
concludes and synthesizes the **Set** result, including the after state of the resource and
25+
the list of changed properties.
26+
- If the field is defined as `state`, DSC expects the resource to emit a JSON Line to stdout
27+
representing the actual state of the resource instance after the **Set** operation changes the
28+
system.
29+
- If the field is defined as `stateAndDiff`, DSC expects the resource to emit two JSON Lines. The
30+
first JSON Line should be an object representing the actual state of the resource after the
31+
**Set** operation. The second JSON Line should be an array representing the names of the
32+
resource properties that the operation changed on the system.
33+
34+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/set?<DOCS_VERSION_PIN>
35+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/set?<DOCS_VERSION_PIN>#return
36+
37+
oneOf:
38+
- title: Null output
39+
description: >-
40+
When a command resource doesn't define `set.return` in its resource manifest, DSC doesn't
41+
expect the resource to emit any JSON to stdout for the **Set** operation.
42+
markdownDescription: |-
43+
***
44+
[_Online Documentation_][00]
45+
***
46+
47+
When a command resource doesn't define [set.return][01] in its resource manifest, DSC doesn't expect
48+
the resource to emit any JSON to stdout for the **Set** operation.
49+
50+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/set?<DOCS_VERSION_PIN>#null-output
51+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/set?<DOCS_VERSION_PIN>#return
52+
type: 'null'
53+
- title: state output
54+
description: >-
55+
When a resource defines `set.return` in its manifest as `state` or `stateAndDiff`, DSC
56+
expects the resource to emit a JSON Line to stdout representing the actual state of the
57+
resource instance after the **Set** operation changes the system.
58+
markdownDescription: |-
59+
***
60+
[_Online Documentation_][00]
61+
***
62+
63+
When a command resource defines [set.return][01] in its manifest as `state` or
64+
`stateAndDiff`, DSC expects the resource to emit a JSON Line to stdout representing the
65+
actual state of the resource instance after the **Set** operation changes the system.
66+
67+
The output must be a JSON object. The object must be a valid representation of an instance of
68+
the resource.
69+
70+
Command resources define their instance schema with the [schema.command][02] or
71+
[schema.embedded][03] fields in their resource manifest. If a command resource returns JSON
72+
that is invalid against the resource instance schema, DSC raises an error.
73+
74+
Adapted resource instances are validated by their adapter when the adapter invokes them.
75+
76+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/set?<DOCS_VERSION_PIN>#state-output
77+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/set?<DOCS_VERSION_PIN>#return
78+
[02]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/command?<DOCS_VERSION_PIN>
79+
[03]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/schema/embedded?<DOCS_VERSION_PIN>
80+
type: object
81+
- title: diff output
82+
description: >-
83+
When a command resource defines `set.return` in its manifest as `stateAndDiff`, DSC expects
84+
the resource to emit a second JSON Line to stdout representing the names of the resource
85+
properties that the operation changed on the system.
86+
markdownDescription: |-
87+
***
88+
[_Online Documentation_][00]
89+
***
90+
91+
When a command resource defines [set.return][01] in its manifest as `stateAndDiff`, DSC
92+
expects the resource to emit a second JSON Line to stdout representing the names of the
93+
resource properties that the operation changed on the system.
94+
95+
This output must be emitted after the JSON Line representing the state of the resource
96+
instance after the operation changes the system.
97+
98+
The output must be a JSON array. The array may be empty, or it may contain one or more
99+
strings. Each string in the array must be the name of one of the resource's properties. Each
100+
string in the array must be unique.
101+
102+
[00]: <DOCS_BASE_URL>/reference/schemas/resource/stdout/set?<DOCS_VERSION_PIN>#diff-output
103+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/set?<DOCS_VERSION_PIN>#return
104+
type: array
105+
uniqueItems: true
106+
items:
107+
type: string

0 commit comments

Comments
 (0)