operation-success-response

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, for OpenAPI 3.x documents.

Examples

Good. The operation declares a 200 response.

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.

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

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.swagger has the details.

commands:
  lint:
    swagger:
      rules:
        operation-success-response: off

Related rules

Further reading

Last updated on View as Markdown
Was this helpful?