Skip to content

Swagger 2: Components Response required: true is not valid swagger Β #941

@simonireilly

Description

@simonireilly

Description

Path parameters are singleton resources, and have the schema of required: true to specify their _require_ment

paths:
  /users/{userId}:
    get:
      summary: Get a user by ID
      parameters:
        - in: path
          name: userId
          schema:
            type: integer
          required: true
          description: Numeric ID of the user to get

Schema response components and request bodies use the required: [] syntax to specify which of the fields in their object structure must be provided.

Assertion

The popular redocly CLI replaced the depreacted swagger cli and can be used to lint the produced swagger 2.

npx @redocly/cli lint doc/apidoc/schema_swagger_json.json 

Benefit

Once there are far fewer errors generated in the swagger 2 file, the errors which are important for user action will be far easier to see, and act upon.

Fix

When generating swagger from ApiPie remove the required: true generated output from the JSON for request bodies and response bodies, but preserve the array definition

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions