Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard response status codes break TypeScript output #1026

Closed
1 task
patrickarlt opened this issue Jan 21, 2023 · 3 comments
Closed
1 task

Wildcard response status codes break TypeScript output #1026

patrickarlt opened this issue Jan 21, 2023 · 3 comments

Comments

@patrickarlt
Copy link

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

@patrickarlt
Copy link
Author

I downgraded to v5 to also work around #984. v5 seems to properly format wildcard status codes as strings "5XX" and non-wildcard codes as numbers 200.

@mitchell-merry
Copy link
Contributor

Was this solved by #1010?

@mitchell-merry
Copy link
Contributor

Looks like it:

export interface operations {

  test: {
    responses: {
      200: components["responses"]["Success"];
      "5XX": components["responses"]["Error"];
    };
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants