Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
906 stars 137 forks source link

How to return the key in message prop with configurable rules syntax #1279

Open jeremyfiel opened 11 months ago

jeremyfiel commented 11 months ago

Is there a way to return the key() where an error occurs with the configurable rules syntax in the message property?

this is an example of what I'm looking for.

In this example, I want the endpoint where the error occurred. I suppose that may even be the Parent Key.

  rule/post-must-define-requestBody:
    severity: error
    message: POST must define a "requestBody" schema in `/path/of/endpoint/with/error`
    subject:
      type: Operation
    where:
      - subject:
          type: Operation
          filterInParentKeys:
            - post
        assertions:
          defined: true
    assertions:
      required:
        - requestBody

this is my current error received, but I want the ability to pass the key into the message body.

validating specs/talent/performance-management/v1/performance-management-configuration-swagger_v1.json...
specs\talent\performance-management\v1\performance-management-configuration-swagger_v1.json:
  786:4  error    rule/post-must-define-requestBody  POST must define a "requestBody" schema

I tried following the docs but it doesn't work.

Problem message displayed if the assertion is false. If omitted, the default message is: "{{assertionName}} failed because the {{subject}} {{property}} didn't meet the assertions: {{problems}}" is displayed. The available placeholders are displayed in that message. In the case there are multiple properties, the {{property}} placeholder produces a comma and space separate list of properties. In case there are multiple problems, the {{problems}} placeholder produces a bullet-list with a new line between each problem.

  rule/post-must-define-requestBody:
    severity: error
    message: POST must define a "requestBody" schema {{property}}
    subject:
      type: Operation
    where:
      - subject:
          type: Operation
          filterInParentKeys:
            - post
        assertions:
          defined: true
    assertions:
      required:
        - requestBody
validating specs/core/questionnaires/v3/tax-statutory-questionnaires-swagger_v3.json...
specs\core\questionnaires\v3\tax-statutory-questionnaires-swagger_v3.json:
  29:4  error    rule/post-must-define-requestBody  POST must define a "requestBody" schema {{property}}
jeremyfiel commented 11 months ago

seems I requested something similar in an earlier conversation. Did you ever make an issue for placeholders? https://github.com/Redocly/redocly-cli/issues/817#issuecomment-1222839131

tatomyr commented 11 months ago

Yeah, the templates seem to be broken. Thanks for reporting! This looks like a bug and an enhancement at the same time.

tatomyr commented 11 months ago

The issue is there's no reference in the --stylish mode and this will allow to show some meaningful output.

jeremyfiel commented 4 months ago

circling back to this.. Any news on progress here?

tatomyr commented 4 months ago

Sorry, haven't had a chance to look into it yet. A lot of other priorities at the moment 😄.