Skip to content

Question: how to support multiple content-types for the same response? #39

@lah-wag

Description

@lah-wag

Hey,

Is it possible to describe a response with multiple content-types using tspec?
Example from: https://swagger.io/docs/specification/describing-responses/

paths:
  /users:
    get:
      summary: Get all users
      responses:
        '200':
          description: A list of users
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArrayOfUsers'
            application/xml:
              schema:
                $ref: '#/components/schemas/ArrayOfUsers'
            text/plain:
              schema:
                type: string

It seems that I would add the mediatype as js-doc to the reponse like in this example: https://ts-spec.github.io/tspec/guide/file-upload-download#file-download

export type UserApiSpec = Tspec.DefineApiSpec<{
  tags: ["Users"];
  paths: {
    "/api/users": {
      get: {
        summary: "Get all users";
        responses: {
          /** @mediaType application/json */
          /** @mediaType text/xml */
          200: Users[];
        };
      };
    };
  };
}>;

But that just takes the last value:

  "/api/users": {
      "get": {
        "operationId": "UserApiSpec_get_/api/users",
        "tags": [
          "Users"
        ],
        "summary": "Get all users",
        "parameters": [],
        "responses": {
          "200": {
            "description": "",
            "content": {
              "text/xml": {
                "schema": {
                  "mediaType": "text/xml",
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Users"
                  }
                }
              }
            }
          }
        }
      }
    }

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions