redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Change context to if and change the object definition

Open RomanHotsiy opened this issue 3 years ago • 2 comments

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

RomanHotsiy avatar Jul 28 '22 13:07 RomanHotsiy

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.

iosypov avatar Sep 01 '22 07:09 iosypov

This issue should be replaced by this:

  1. Add support for 3 additional locator properties: filterInParentKeys, filterOutParentKeys, matchParentKeys (regex).

  2. Change context to if.

  3. Change if list to conform to assertion object (see the docs -- if, message, suggest, severity are ignored when used inside of the if list. The assertion object in the if list must contain the subject and at least one assertion (such as defined: true).

See the proposed docs for more details: https://github.com/Redocly/redocly-cli/pull/857

adamaltman avatar Sep 21 '22 21:09 adamaltman

I'm closing this as we have the newer syntax version: https://github.com/Redocly/redocly-cli/pull/917

tatomyr avatar Oct 28 '22 17:10 tatomyr