redocly-cli
redocly-cli copied to clipboard
Change context to if and change the object definition
Is your feature request related to a problem? Please describe.
The context object allows for targeting exact keys. However, sometimes you need more flexibility and want to target based on some specific parent property value
Describe the solution you'd like
Context object (current)
| Property | Type | Description |
|---|---|---|
| type | string |
REQUIRED. One of the OpenAPI node types. |
| matchParentKeys | [string] |
The list of parent object key names to evaluate with respect to the subject. |
| excludeParentKeys | [string] |
The list of parent object key names to not evaluate with respect to the subject. |
Context object (desired)
| Property | Type | Description |
|---|---|---|
| type | string |
REQUIRED. One of the OpenAPI node types. |
| includeParentKeys | [string] |
The list of the exact parent object key names to evaluate with respect to the subject. |
| excludeParentKeys | [string] |
The list of the exact parent object key names to not evaluate with respect to the subject. |
| includeByPropValue | [PropMatcher] | A list of prop matchers. They are combined using boolean AND. Subject is evaluated if all the matchers apply. |
| excludeByPropValue | [PropMatcher] | A list of prop matchers. They are combined using boolean AND. Subject is not evaluated if all the matchers apply. |
PropMatcher object (desired)
| Property | Type | Description |
|---|---|---|
| key | string |
REQUIRED. The property key |
| value | any |
[any] |
Example usage:
assert/only-string-in-params:
context:
- type: Operation
matchParentKeys: [put]
- type: Parameter
includeByPropValue:
- key: in # we can validate the key value!
value: ["query", "path"]
subject: Schema
property: type
enum: ["string"]
Describe alternatives you've considered
Make it a bit more simple without support for multiple matchers.
Additional context
Related to https://github.com/Redocly/redocly-cli/issues/714 Some more context in: https://github.com/Redocly/intranet/issues/370#issuecomment-1196703294
I think it will great to have ability to include parent key not only exact matching key and by regex. It can be make more flexibility.
Also, when I worked on assertions I think it will be nice to have posibility add conditions by property. So I like this issue.
And I have on idea. I think it will useful to have something like debug mode. In this mode user can see which elements selected and why.
- Like a simple, just output in console this stuff.
- Maybe some vs code extension, which help debug and highlight elements in openapi.
- VS Code extension that help you make context. Right mouse click -> get context -- and generate context for this element.
This issue should be replaced by this:
-
Add support for 3 additional locator properties:
filterInParentKeys,filterOutParentKeys,matchParentKeys(regex). -
Change
contexttoif. -
Change
iflist to conform toassertionobject (see the docs --if,message,suggest,severityare ignored when used inside of theiflist. The assertion object in theiflist must contain the subject and at least one assertion (such asdefined: true).
See the proposed docs for more details: https://github.com/Redocly/redocly-cli/pull/857
I'm closing this as we have the newer syntax version: https://github.com/Redocly/redocly-cli/pull/917