Skip to content

Wildcard response status codes break TypeScript output #1026

Closed
@patrickarlt

Description

@patrickarlt

Description

TypeScript is treating the numeric status codes as invalid TypeScript and is throwing error when wildcard status codes like 5XX are used. You can see the output and errors in the TypeScript playground.

2023-01-20_16-03-16

Name Version
openapi-typescript 6.10.0 - from npx
Node.js 16.16.x
OS + version macOS 12

Reproduction

  1. Convert the following spec.
  2. Copy/paste the resulting TypeScript file into the TypeScript playground](https://www.typescriptlang.org/play)
  3. See the error around the 5xx status code
openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0
servers:
  - url: https://my-api.com
    description: Test
paths:
  /path:
    get:
      operationId: test
      responses:
        "200":
          $ref: "#/components/responses/Success"
        "5XX":
          $ref: "#/components/responses/Error"
components:
  responses:
    Success:
      description: A response
      content:
        application/json:
          schema:
            type: string
    Error:
      description: Details
      content:
        application/json:
          schema:
            type: string

Expected result

Response codes should probably be strings. The spec states that the responses objects keys should always be quoted.

This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character X. For example, 2XX represents all response codes between [200-299].

It seems like the spec really intends for this to be a string. Searching around I think this might have been introduced in #381?

Checklist

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