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

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

Open jeremyfiel opened this issue 10 months ago • 5 comments

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 avatar Oct 02 '23 15:10 jeremyfiel

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

jeremyfiel avatar Oct 03 '23 21:10 jeremyfiel

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

tatomyr avatar Oct 11 '23 15:10 tatomyr

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

tatomyr avatar Oct 11 '23 16:10 tatomyr

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

jeremyfiel avatar May 06 '24 21:05 jeremyfiel

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

tatomyr avatar May 20 '24 11:05 tatomyr