# paths-sorted

Source: https://apigenie.pl/docs/linter/swagger/rules/paths-sorted

A rule of the Swagger 2.0 linter, which reads Swagger 2.0 documents; OpenAPI 3 documents go to the OpenAPI linter. Since 0.9.0. Fixed by `--fix`. In the rulesets: Strict at error, All at error.

This rule checks whether the paths of a Swagger 2.0 document are sorted.

## Rule details

Sorted paths make a large document easier to navigate and keep diffs small
when paths are added.

The `paths-sorted` rule walks the entries of the root `paths` object in the
order they appear in the document and reports `Paths are not sorted: <path>`
for every path that is not greater than the previous one. Paths are compared
character by character (byte order), so `/Pets` sorts before `/pets` and
`/pets` before `/pets/{id}`.

The OpenAPI linter has a rule of the same name,
[paths-sorted](/docs/linter/openapi/rules/paths-sorted), for OpenAPI 3.x documents.

Turn the rule off when paths are intentionally grouped in another order, for example by resource or
by workflow.

## Examples

**Good**. The paths are sorted.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
paths:
  /owners:
    get:
      responses:
        '200':
          description: A list of owners.
  /pets:
    get:
      responses:
        '200':
          description: A list of pets.
```

**Bad**. `/owners` is listed after `/pets`.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
paths:
  /pets:
    get:
      responses:
        '200':
          description: A list of pets.
  /owners:
    get:
      responses:
        '200':
          description: A list of owners.
```

## Automatic fixes

`--fix` reorders the entries of the `paths`
object so that the paths are sorted in byte order.
