-
Notifications
You must be signed in to change notification settings - Fork 28
feat: adds a parameter object for the action object #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
3ec7b0d
9c32a1f
8979e9f
1ed3eb3
84ef0ba
be51b60
daaa64e
8e74d35
a10b0dc
1ae6e32
0f15483
89eb5af
012debd
68e13ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Invalid Parameters - Missing Name | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - values: | ||
| - "value1" | ||
| - "value2" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Invalid Parameters - Default Values with nested objects | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: testParam | ||
| defaultValues: | ||
| - value1: | ||
| key1: | ||
| subKey2: "sub-value2" | ||
| - "value2" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Invalid Parameters - Default Values with nested objects | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: testParam | ||
| defaultValues: | ||
| - value1: | ||
| key1: | ||
| subKey2: "sub-value2" | ||
| - value2: | ||
| key2: | ||
| subKey2: "sub-value2" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Valid Parameters - Default values mapping | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: param1 | ||
| defaultValues: | ||
| - key: "value1" | ||
| value: "VALUE1" | ||
| - key: "value2" | ||
| value: "VALUE2" | ||
| - key: "value3" | ||
| value: "VALUE3" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Valid Parameters - Default values | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: param1 | ||
| defaultValues: | ||
| - "value1" | ||
| - "value2" | ||
| - "value3" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Valid Parameters - Multiple Parameters | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: inlineParam | ||
| defaultValues: | ||
| - "dev" | ||
| - "staging" | ||
| - "prod" | ||
| - name: envParam1 | ||
| - name: envParam2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Valid Parameters - Environment | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: envParam |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Valid Parameters - With Extensions | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get | ||
| parameters: | ||
| - name: paramWithExt | ||
| defaultValues: | ||
| - "value1" | ||
| - "value2" | ||
| x-custom-extension: "custom value" | ||
| x-another-extension: 42 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ This object represents one or more changes to be applied to the target document | |
| | <a name="action-update"></a>update | Any | If the `target` selects object nodes, the value of this field MUST be an object with the properties and values to merge with each selected object. If the `target` selects array nodes, the value of this field MUST be an array to concatenate with each selected array, or an object or primitive value to append to each selected array. If the `target` selects primitive nodes, the value of this field MUST be a primitive value to replace each selected node. This field has no impact if the `remove` field of this action object is `true` or if the `copy` field contains a value. | | ||
| | <a name="action-copy"></a>copy | `string` | A JSONPath expression selecting a single node to copy into the `target` nodes. If the `target` selects object nodes, the value of this field MUST be an object with the properties and values to merge with each selected object. If the `target` selects array nodes, the value of this field MUST be an array to concatenate with each selected array, or an object or primitive value to append to each selected array. If the `target` selects primitive nodes, the value of this field MUST be a primitive value to replace each selected node. This field has no impact if the `remove` field of this action object is `true` or if the `update` field contains a value. | | ||
| | <a name="action-remove"></a>remove | `boolean` | A boolean value that indicates that each of the target nodes MUST be removed from the the map or array it is contained in. The default value is `false`. | | ||
| | <a name="action-parameters"></a> | [[Parameter Object](#parameter-object)] | An array of parameter objects to use and expand the action definition. MAY contain zero or more parameters. Parameters MUST have unique names across the collection. Default `undefined`. | | ||
|
|
||
| If the `target` JSONPath expression selects zero nodes, the action succeeds without changing the target document. | ||
| If the `target` JSONPath expression selects two or more nodes for an `update` or `copy` action, the selected nodes MUST be either all objects or all arrays or all primitives. | ||
|
|
@@ -134,6 +135,31 @@ The properties of the `update` or `copy` object MUST be compatible with the targ | |
|
|
||
| This object MAY be extended with [Specification Extensions](#specification-extensions). | ||
|
|
||
| ### Parameter Object | ||
|
|
||
| The object represents parameters that can be used with actions. | ||
baywet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Fixed Fields | ||
|
|
||
| | Field Name | Type | Description | | ||
| | ---- | :----: | ---- | | ||
| | <a name="parameter-name"></a>name | `string` | **REQUIRED** A name for the parameter that is unique per action. The name MUST match the following regular expression `[a-zA-Z-0-9]+`. | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add note that same name in different actions means same environment variable value in all actions. Which also makes different default values questionable. |
||
| | <a name="parameter-default-values"></a>defaultValues | [`string`] or [Map(`string`, `string`] | The values to use in case the environment variable is not defined. MAY contain zero or more entries. When values contains multiple entries, the action is effectively projected for each of the entries of the parameter. If multiple parameters are defined for any given action, parameters effectively act as a matrix definition and the action should be projected across each dimension. | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there is no way to say "don't look in the environment, just use these values". Is that intentional?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was one reservation I had as well which is why I initially had the source enum in place.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ralfhandl I'd like your input on this one please since you helped me refactor into a simpler syntax, we kind of lost a capability in the process.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another possible approach, which I admit adds some complexity, but also a lot of flexibility, is to specify a value (or values) for the parameter with an "expression", similar to what is done for Link Objects in OpenAPI. https://spec.openapis.org/oas/v3.1.1.html#runtime-expressions |
||
|
|
||
| #### Parameter Expressions | ||
|
|
||
| Parameter expressions MAY be used in any field defined by the Action Object except for parameters. The syntax for parameter expressions is the following `${parameter_name}` or `${parameter_name.value_key}` if the value is a record of strings. ONLY parameter expressions with a matching parameter definition for the action MAY be replaced by their values. | ||
|
|
||
| If an action defines a parameter which resolves multiple values, the parameter acts as a dimension for the action, and the parameterized action is effectively projected into multiple resolved actions before they are being applied to the target document. | ||
|
|
||
| #### Environment Variable values | ||
|
|
||
| The environment variable MAY ONLY contain: | ||
|
|
||
| - A simple string `foo`. | ||
| - A JSON array of strings `["foo", "bar"]`. | ||
| - A JSON array of records of strings `[{"description": "foo", "target": "FOO"}, {"description": "bar", "target": "BAR"}]`. | ||
|
|
||
| ### Examples | ||
|
|
||
| #### Structured Overlay Example | ||
|
|
@@ -536,6 +562,61 @@ paths: | |
| description: OK | ||
| ``` | ||
|
|
||
| #### Parameter example | ||
|
|
||
| This example shows how action parameters can be used to define multiple actions from a single one. | ||
|
|
||
| ```yaml | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Makes a matrix projection | ||
| version: 1.0.0 | ||
| actions: | ||
| - description: Adds component schema ${foo}-${bar.description} | ||
baywet marked this conversation as resolved.
Show resolved
Hide resolved
baywet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| target: '$.components.schemas["${foo}${bar.target}"]' | ||
| parameters: | ||
| - name: foo | ||
| # using simple strings as default values | ||
| defaultValues: | ||
| - one | ||
| - two | ||
| - name: bar | ||
| # using records as default values | ||
| defaultValues: | ||
| - description: a | ||
| target: ALPHA | ||
| - description: b | ||
| target: BETA | ||
| update: | ||
| someProperty: "Fizz ${foo}-${bar.description} buzz" | ||
| ``` | ||
|
|
||
| Is equivalent to defining | ||
|
|
||
| ```yaml | ||
| overlay: 1.1.0 | ||
| info: | ||
| title: Makes a matrix projection | ||
| version: 1.0.0 | ||
| actions: | ||
| - description: Adds component schema one-a | ||
| target: '$.components.schemas["oneALPHA"]' | ||
| update: | ||
| someProperty: "Fizz one-a buzz" | ||
| - description: Adds component schema one-b | ||
| target: '$.components.schemas["oneBETA"]' | ||
| update: | ||
| someProperty: "Fizz one-b buzz" | ||
| - description: Adds component schema two-a | ||
| target: '$.components.schemas["twoALPHA"]' | ||
| update: | ||
| someProperty: "Fizz two-a buzz" | ||
| - description: Adds component schema two-b | ||
| target: '$.components.schemas["twoBETA"]' | ||
| update: | ||
| someProperty: "Fizz two-b buzz" | ||
| ``` | ||
|
|
||
| ### Specification Extensions | ||
|
|
||
| While the Overlay Specification tries to accommodate most use cases, additional data can be added to extend the specification at certain points. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.