# `respect`

## Introduction

Use this command to execute API tests described in an Arazzo description.

**Important**

The `respect` command supports Arazzo 1.0.1 descriptions.
Of the features added in Arazzo 1.1.0, it supports only these:

- The `parameters` field of success and failure actions.
  When an action references a workflow with `workflowId`, `respect` passes the action's parameters to that workflow as inputs.
- The [`querystring` parameter location](#parameters-with-in-querystring).
- [Selector Objects](#selector-objects) with a `jsonpath` or `jsonpointer` type.

AsyncAPI source descriptions are not supported either; if you need them, upvote or open an issue in the [Redocly CLI repository](https://github.com/Redocly/redocly-cli/issues).

## Usage

```sh
npx @redocly/cli@latest respect <your-test-file | multiple files | files bash query> [-w | --workflow] [-s | --skip] [-v | --verbose] [-i | --input] [-S | --server] [-H | --har-output] [-J | --json-output] [--max-steps] [--max-fetch-timeout] [--execution-timeout] [--severity] [--no-secrets-masking]
```

## Options

| Option | Type | Description |
| --- | --- | --- |
| -w, --workflow | [string] | Workflow names from the test file to run. For example, the following command runs "first-flow" and "second-flow" workflows from the `test-file.yaml` Arazzo description:  `npx @redocly/cli@latest respect test-file.yaml --workflow first-flow second-flow`  The `--workflow` option can't be used with `--skip`. |
| -s, --skip | [string] | Workflow names from the test file to skip. For example, the following command skips the "first-flow" workflow from the `test-file.yaml` Arazzo description:  `npx @redocly/cli@latest respect test-file.yaml --skip first-flow`  **Warning**  The `--skip` option can't be used with `--workflow`. |
| -v, --verbose | boolean | Runs the command in verbose mode to help with troubleshooting issues. For example, the following command runs all workflows from the `test-file.yaml` Arazzo description in verbose mode:  `npx @redocly/cli@latest respect test-file.yaml --verbose` |
| --har-output | string | Path for the `har` file for saving logs. For example, the following command runs all workflows from the `test-file.yaml` Arazzo description and saves the logs to the `logs.har` file:  `npx @redocly/cli@latest respect test-file.yaml --har-output='logs.har'` |
| --json-output | string | Path for the JSON file for saving logs. For example, the following command runs all workflows from the `test-file.yaml` Arazzo description and saves the logs to the `logs.json` file:  `npx @redocly/cli@latest respect test-file.yaml --json-output='logs.json'` |
| --input | string | Input parameters with values that are mapped to the workflow inputs description. Before a workflow runs, `respect` checks its inputs against the workflow's `inputs` schema. Inputs that don't match the schema produce a warning, and the workflow still runs with the inputs as given. For example, the following command maps the "userEmail" and "userPassword" inputs and values to all workflows in the `test.yaml` Arazzo description:  `npx @redocly/cli@latest respect test.yaml --input userEmail=name@redocly.com --input userPassword=12345`  You can also use an environment variable to set the input, as in the following example:  `REDOCLY_CLI_RESPECT_INPUT='userEmail=name@redocly.com,userPassword=12345' npm run cli respect test.yaml`  You can also include nested values. The following example command maps the `nestedKey` input and its value to all workflows in the `test-file.yaml` Arazzo description:  `npx @redocly/cli@latest respect test-file.yaml --input '{"key": "value", "nested": {"nestedKey": "nestedValue"}}'`  You can also use an environment variable to set the input, as in the following example:  `REDOCLY_CLI_RESPECT_INPUT='{"key":"value","nested":{"nestedKey":"nestedValue"}}' npx @redocly/cli@latest respect test-file.yaml` |
| --server | string | Server overrides for the `sourceDescriptions` object. For example, the following command runs all workflows from the `test-file.yaml` Arazzo description. Instead of the servers listed in the API description, it uses the specified servers:  `npx @redocly/cli@latest respect test-file.yaml --server sourceDescriptionName1=https://test.com --server sourceDescriptionName2=https://test2.com`  You can also pass multiple server overrides as an environment variable by separating them with commas, as in the following example:  `REDOCLY_CLI_RESPECT_SERVER="sourceDescriptionName1=https://test.com,sourceDescriptionName2=https://test2.com"` |
| --severity | string | Severity of the check. Customize the severity level of validation checks for status codes, schemas, and content types. Setting the severity level is useful when:  - You're actively developing your API and want to temporarily relax validation. - You're testing new API behavior that doesn't match the current schema. - You've encountered known issues that shouldn't block test execution. - You want to treat certain validation failures as warnings instead of errors.  The following checks can be configured:  - `STATUS_CODE_CHECK`: Verifies if the status code returned with API responses matches the statuses described in the provided OpenAPI description. - `SCHEMA_CHECK`: Verifies if the response body schema matches what is defined in the provided OpenAPI description. - `SUCCESS_CRITERIA_CHECK`: Verifies if the success criteria defined in the provided Arazzo description has been met. - `CONTENT_TYPE_CHECK`: Verifies if the `Content-Type` matches what is defined in the provided OpenAPI description.  The following severity values are available:  - `error`: Validation failures cause the workflow to fail. - `warn`: Validation failures appear as warnings but don't fail the workflow. - `off`: Validation checks still run, but their results are ignored.  Setting the severity of a check to `off` doesn't prevent the check from running. It only stops the check's results from affecting the workflow outcome.  For example, the following command sets status code errors to the warning severity level:  `npx @redocly/cli respect test-file.yaml --severity='{"STATUS_CODE_CHECK":"warn"}'` |
| --max-steps | number | Maximum number of steps to run (default: 2000). For example, the following command sets the maximum number of steps to 50:  `npx @redocly/cli@latest respect test-file.yaml --max-steps=50`  You can also pass the maximum number of steps as an environment variable, as in the following example:  `REDOCLY_CLI_RESPECT_MAX_STEPS=50 npx @redocly/cli@latest respect test-file.yaml` |
| --max-fetch-timeout | number | Maximum time to wait for API response per request in milliseconds (default: 40 seconds). For example, the following command sets the maximum fetch timeout to 60 seconds:  `npx @redocly/cli@latest respect test-file.yaml --max-fetch-timeout=60000`  You can also pass the maximum time to wait as an environment variable, as in the following example:  `REDOCLY_CLI_RESPECT_MAX_FETCH_TIMEOUT=60000 npx @redocly/cli@latest respect test-file.yaml` |
| --execution-timeout | number | Maximum time to wait for the Respect execution in milliseconds (default: 1 hour). For example, the following command sets the execution timeout to 30 minutes:  `npx @redocly/cli@latest respect test-file.yaml --execution-timeout=1800000`  You can also pass the maximum time to wait as an environment variable, as in the following example:  `REDOCLY_CLI_RESPECT_EXECUTION_TIMEOUT=1800000 npx @redocly/cli@latest respect test-file.yaml` |
| --no-secrets-masking | boolean | Disables masking of secrets in the output. By default, `respect` masks sensitive information with `********` in both terminal logs and file outputs. Sensitive information includes values described with `format: password`, and tokens and authentication headers from `x-security`.  When this flag is set to `true`, the raw (unmasked) data shows in all outputs.  For example, the following command disables sensitive output masking:  `npx @redocly/cli@latest respect test-file.yaml --no-secrets-masking` |

## Request data from the API description

A step that calls an operation doesn't have to list its parameters or request body.
When the step leaves them out, `respect` takes them from the OpenAPI description:

- Without `parameters`, the step sends the operation's required parameters, including the ones defined on the path.
- Without `requestBody`, the step sends a body for the first media type of the operation's request body.

Each value comes from the `example` field, or from the first entry in `examples` (its `value` or, in OpenAPI 3.2, its `dataValue`).
Without an example, `respect` generates a value from the schema.

For example, if the `orderId` path parameter of `getOrderById` has the example `ord_01h1s5z6vf2mm1mz3hevnn9va7`, the following step sends `GET /orders/ord_01h1s5z6vf2mm1mz3hevnn9va7`:

```yaml
steps:
  - stepId: get-order
    operationId: getOrderById
```

A step that lists any `parameters` takes no parameters from the description.
List every required parameter in that step.

## Parameters with `in: querystring`

A parameter with `in: querystring` sets the whole query string of the request.
It needs an Arazzo 1.1.0 description.
Its value must be a string, and a request cannot combine it with `query` parameters or with another `querystring` parameter.

```yaml
steps:
  - stepId: list-menu-items
    operationId: listMenuItems
    parameters:
      - in: querystring
        name: filters
        value: search={$inputs.search}&limit=5
```

`respect` sends the value as written, except for `#`, which it percent-encodes.
If the OpenAPI description declares a media type other than `application/x-www-form-urlencoded` for the parameter, `respect` percent-encodes the whole value.

A step without `parameters` takes a required `querystring` parameter from the OpenAPI description.
The value comes from the examples of the parameter, then from the examples or the schema of its media type.
For `application/x-www-form-urlencoded`, an array property repeats its name for each item, and an object is sent as JSON.
`respect` does not apply the `encoding` field of a media type, for a `querystring` parameter or for a request body.

The parameters that a workflow or a step sets take priority.
`respect` does not take a `querystring` parameter from the OpenAPI description when the workflow or the step sets `query` or `querystring` parameters.
It does not take `query` parameters from the OpenAPI description when the workflow or the step sets a `querystring` parameter.

## Selector Objects

A Selector Object picks a value from structured data, such as a response body.
`respect` evaluates a Selector Object in these places:

- step and workflow `outputs`
- the `value` of a parameter of a workflow, a step, or a success or failure action
- a request body `payload`
- the `value` of a replacement

A Selector Object in `outputs` needs an Arazzo 1.1.0 description.
The other places accept a Selector Object in an Arazzo 1.0.1 description too.
The `context` is a runtime expression that gives the data, and the `selector` picks a value from that data.

```yaml
steps:
  - stepId: list-menu-items
    operationId: listMenuItems
    outputs:
      menu: $response.body
      dessertIds:
        context: $response.body
        selector: $.items[?(@.category == "dessert")].id
        type: jsonpath
      pageLimit:
        context: $response.body
        selector: /page/limit
        type: jsonpointer
  - stepId: get-menu-item-photo
    operationId: getMenuItemPhoto
    parameters:
      - in: path
        name: menuItemId
        value:
          context: $steps.list-menu-items.outputs.menu
          selector: $.items[0].id
          type: jsonpath
```

`respect` supports the `jsonpath` selector type, as defined in RFC 9535, and the `jsonpointer` selector type.
A step with a selector of another type or version fails.

- A `jsonpointer` selector gives the value at the pointer.
  The pointer is empty or starts with `/`.
- A `jsonpath` selector that consists only of names and indexes, such as `$.items[0].id`, gives the value it selects.
- Any other `jsonpath` selector, such as one with a filter, a wildcard, or a slice, gives the list of the values it selects.
  The result is a list also when the selector selects one value or none.
  Read an item of that list with a JSON Pointer, as in `$steps.list-menu-items.outputs.dessertIds#/0`.

The step fails when a `jsonpointer` selector, or a `jsonpath` selector of names and indexes, selects no value.

A selector reads the keys of its `context` as they are, so with `context: $response.body` the selector `$['special-note']` selects the `special-note` key.
An output that a runtime expression saves, such as `menu: $response.body`, has the hyphens in its keys replaced with underscores.
A selector on that output reads the same key as `$.special_note`, and a `jsonpath` success criterion reads it as `@.special_note`, as in `$[?(@.special_note == "no-sugar")]`.

A `jsonpath` selector can embed runtime expressions in curly braces, for example `$.items[?(@.category == "{$inputs.category}")].id`.
Inside a quoted string, `respect` inserts the text of the value.
Outside a quoted string, as in `$.items[?(@.category == {$inputs.category})].id`, it inserts a string value together with its quotes.

A Selector Object has a `context`, a `selector`, and a `type` of `jsonpath`, `xpath`, or `jsonpointer`.
`respect` reads every object with these fields as a Selector Object.
A request body cannot send such an object as a literal value.

## Examples

- Run the tests by running the following command: `npx @redocly/cli@latest respect <your-test-file>`.
- Run multiple tests by running the following command: `npx @redocly/cli@latest respect <your-test-file-one> <your-test-file-two>`.
- Run multiple tests by running the following command with bash selector : `npx @redocly/cli@latest respect $(find ./path-to-tests-folder -type f -name '*.arazzo.yaml')`.

**Example output**

```bash
Running workflow warp.arazzo.yaml / missionLostInvention

  ✓ POST /anchors - step setAnchorToCurrentTime
    ✓ status code check (Response code 201 matches one of description codes: [201, 409])
    ✓ content-type check
    ✓ schema check

  ✓ POST /timelines - step createTimelineTo1889
    ✓ status code check (Response code 201 matches one of description codes: [201])
    ✓ content-type check
    ✓ schema check

  ✓ POST /travels - step travelTo1889
    ✓ status code check (Response code 200 matches one of description codes: [200, 400])
    ✓ content-type check
    ✓ schema check

  ✓ POST /items - step findAndRegisterBlueprint
    ✓ status code check (Response code 200 matches one of description codes: [200, 409])
    ✓ content-type check
    ✓ schema check

  ✓ POST /paradox-checks - step avoidParadox
    ✓ success criteria check
    ✓ success criteria check
    ✓ status code check (Response code 200 matches one of description codes: [200, 400])
    ✓ content-type check
    ✓ schema check

  ✓ POST /travels - step returnToPresent
    ✓ status code check (Response code 200 matches one of description codes: [200, 400])
    ✓ content-type check
    ✓ schema check

  Summary for warp.arazzo.yaml
  
  Workflows: 1 passed, 1 total
  Steps: 6 passed, 6 total
  Checks: 20 passed, 20 total
  Time: 1060ms

┌──────────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┬─────────┐
│ Filename                                                 │ Workflows  │ Passed  │ Failed  │ Warnings │ Skipped │
├──────────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┼─────────┤
│ ✓ warp.arazzo.yaml                                       │ 1          │ 1       │ -       │ -        │ -       │
└──────────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┴─────────┘
```

## Resources

- Learn more about using mTLS with Respect in [Use mTLS](https://redocly.com/docs/respect/guides/mtls-cli).
- Follow steps to test API sequences in [Test a sequence of API calls](https://redocly.com/docs/respect/guides/test-api-sequences).
- Learn what Respect is and how you can use it to test API in the [Respect](https://redocly.com/docs/respect) concept document.
- [Learn Arazzo](https://redocly.com/learn/arazzo/what-is-arazzo).
