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

Fix 2XX, 4XX, 5XX responses #1251

Merged
merged 2 commits into from
Jul 26, 2023
Merged

Fix 2XX, 4XX, 5XX responses #1251

merged 2 commits into from
Jul 26, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Jul 26, 2023

Changes

Adds support for 2XX, 4XX, and 5XX responses in schema, which is supported by the spec.

Funny enough, I have never used this or seen this; just happened to skim over that definition and saw it was allowed. In openapi-typescript we just skip right over this and never needed to parse it (still added a test just to be sure). But openapi-fetch requires all valid status codes explicitly stated for TS inference to work.

So for that one random person out there using this in your schema, this goes out to you 🥂

How to Review

Tests should pass.

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (only applicable for openapi-typescript)

@changeset-bot
Copy link

changeset-bot bot commented Jul 26, 2023

🦋 Changeset detected

Latest commit: bd72890

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -29,9 +29,9 @@ export interface OperationObject {
responses: any;
}
export type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
export type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207;
export type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207 | "2XX";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random fact: the status codes are numbers because that’s what openapi-typescript actually exports. See #380

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 26, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: bd72890
Status: ✅  Deploy successful!
Preview URL: https://bf99acf2.openapi-ts.pages.dev
Branch Preview URL: https://fix-ranges.openapi-ts.pages.dev

View logs

expect(generated).toBe(`{
responses: {
/** @description OK */
"2XX": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 Glad this worked! Added a test just cuz I got scared

@drwpow drwpow merged commit 80717a7 into main Jul 26, 2023
@drwpow drwpow deleted the fix-ranges branch July 26, 2023 17:16
@github-actions github-actions bot mentioned this pull request Jul 26, 2023
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

Successfully merging this pull request may close these issues.

1 participant