# paths-max-depth

Source: https://apigenie.pl/docs/linter/openapi/rules/paths-max-depth

A rule of the OpenAPI linter, which reads OpenAPI 3.0, 3.1 and 3.2 documents. Since 0.0.1. In the rulesets: Recommended at warning, Strict at warning, All at error.

This rule checks that no path has more than 4 segments, or the number configured. A segment is
the text between two slashes; `/users/{userId}/posts` has three.

## Rule details

A path of six segments spells out a chain of ownership that the client must walk on every
request, `/users/{userId}/posts/{postId}/comments/{commentId}`, when the last identifier alone
names the resource. Shorter paths are easier to read, to route and to keep when the ownership
changes.

The rule reports `Path URL is too much nested (...)` on each path over the limit.

## Configuration

A positive integer: the number of segments allowed. 4 by default.

**Configuration example**. Up to 6 segments.

```yaml
commands:
  lint:
    rules:
      paths-max-depth:
        - warning
        - 6
```

## Examples

**Good**. Two segments.

```yaml
paths:
  /users/{userId}:
    get:
      summary: Get a user by ID
```

**Bad**. Six segments with the default limit.

```yaml
paths:
  /users/{userId}/posts/{postId}/comments/{commentId}:
    get:
      summary: Get a comment of a post of a user
```
