Skip to content

Support multiple successful responses based on status codeΒ #385

@daniel-v

Description

@daniel-v

Use case

Assume we are working with an API that returns a List<String> for the owner's pet names.

There are 2 successful branches here:

  1. 200 - a body with appropriate content-length header and the list of pet name
  2. 204 - No-Content which results in content-length: 0. The owner does not yet have any pets

Currently, if both 200 and 204 are specified and No-Content response returns with empty body, an exception will be thrown.

Error: Null check operator used on a null value

because the generated code uses ! operator on .data field of result.

What I'm looking for is the ability to be able to do something like this:

openapi: 3.0.4
info:
  title: Mini pets
  version: "1.0"
paths:
  /pets:
    get:
      summary: Gets the list of pets
      responses:
        200:
          description: List of pet names
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
        204:
          description: No pets yet

Proposal

In such situations, returning with a freezed union type would probably cover the usecase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions