Ensure each operation define at least one success response

Ensure that each operation in the OpenAPI document defines at least one success response. A success response is a response with a status code in the range of 200 to 299, indicating that the operation was completed successfully. A success response should have a description and a content property that defines the media type and the schema of the response body. Defining at least one success response for each operation helps both humans and computers to understand what kind of data they can expect from the API. It also helps to validate and document the API, as well as to generate client and server code from the OpenAPI document.

Risk Level: high
Platform: OpenAPI
Spectral Rule ID: OPENAPI020

REMEDIATION

Add or modify the responses property for each operation in the OpenAPI document and define at least one success response with a status code as declare in the table blow:

OperationStatus Codes
delete200, 201, 202, 204
patch200, 201, 202, 204
post200, 201, 202, 204
put200, 201, 202, 204
head200, 202
get200, 202

Status Description:

StatusDescription
200OK
201Created
202Accepted
204No Content

For exmaple:

openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
servers:
  - url: https://api.example.com/v1
+ # Add or modify the responses property for each operation in the OpenAPI document
  paths:
    /pets:
      get:
        summary: List all pets
        responses:
+         '200':
+           description: A list of pets
+           content:
+             application/json:
+               schema:
+                 type: array
+                 items:
+                   $ref: '#/components/schemas/Pet'
      post:
        summary: Create a new pet
        requestBody:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        responses:
+         '201':
+           description: Pet created successfully
+           content:
+             application/json:
+               schema:
+                 $ref: '#/components/schemas/Pet'
+               content:
+                 application/json:
+                   schema:
+                     type: object
+                     properties:
+                       message:
+                         type: string

Read more: