# operation-success-response

Source: https://api-genie.dev/docs/linter/swagger/rules/operation-success-response

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. In the rulesets: Recommended at error, Strict at error, All at error.

This rule checks whether every operation of a Swagger 2.0 document declares at
least one success response.

## Rule details

Consumers and code generators rely on the success response of an operation to
know what a successful call returns. An operation that only documents errors
leaves that unspecified.

The `operation-success-response` rule reports `Operation must have at least
one success response` for every operation whose responses contain no status
code starting with `2` or `3` and no `default` response.

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

## Examples

**Good**. The operation declares a `200` response.

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

**Bad**. The operation only declares error responses.

```yaml
swagger: '2.0'
info:
  title: Pet Store
  version: 1.0.0
paths:
  /pets:
    get:
      responses:
        '400':
          description: Invalid request.
        '500':
          description: Internal error.
```
