New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openapi-typescript-helpers

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-typescript-helpers - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

biome.json

23

CHANGELOG.md
# openapi-typescript-helpers
## 0.0.9
### Patch Changes
- Improved handling of `SuccessResponse<T>` and `ErrorResponse<T>`
- Changed handling of `ErrorResponse<T>` to produce one and only one error type (rather than an impossible union)
## 0.0.8

@@ -7,5 +14,5 @@

- [#1610](https://github.com/drwpow/openapi-typescript/pull/1610) [`cc8073b`](https://github.com/drwpow/openapi-typescript/commit/cc8073b3ee42e7aaa546a9c6a0553c300d8882de) Thanks [@illright](https://github.com/illright)! - Fix data/error discrimination when there are empty-body errors
- [#1610](https://github.com/openapi-ts/openapi-typescript/pull/1610) [`cc8073b`](https://github.com/openapi-ts/openapi-typescript/commit/cc8073b3ee42e7aaa546a9c6a0553c300d8882de) Thanks [@illright](https://github.com/illright)! - Fix data/error discrimination when there are empty-body errors
- [#1559](https://github.com/drwpow/openapi-typescript/pull/1559) [`6fe2c85`](https://github.com/drwpow/openapi-typescript/commit/6fe2c856331e910b9c8376fc151d63028dcfba11) Thanks [@drwpow](https://github.com/drwpow)! - Simplify build
- [#1559](https://github.com/openapi-ts/openapi-typescript/pull/1559) [`6fe2c85`](https://github.com/openapi-ts/openapi-typescript/commit/6fe2c856331e910b9c8376fc151d63028dcfba11) Thanks [@drwpow](https://github.com/drwpow)! - Simplify build

@@ -16,3 +23,3 @@ ## 0.0.7

- [#1479](https://github.com/drwpow/openapi-typescript/pull/1479) [`c6d945b`](https://github.com/drwpow/openapi-typescript/commit/c6d945be717bb3999178fb3a77292e41e1b7ab80) Thanks [@darwish](https://github.com/darwish)! - Fixed build of openapi-typescript-helpers for CommonJS environments
- [#1479](https://github.com/openapi-ts/openapi-typescript/pull/1479) [`c6d945b`](https://github.com/openapi-ts/openapi-typescript/commit/c6d945be717bb3999178fb3a77292e41e1b7ab80) Thanks [@darwish](https://github.com/darwish)! - Fixed build of openapi-typescript-helpers for CommonJS environments

@@ -23,3 +30,3 @@ ## 0.0.6

- [#1458](https://github.com/drwpow/openapi-typescript/pull/1458) [`23517a2`](https://github.com/drwpow/openapi-typescript/commit/23517a2c2ab94d49085391130cd7d11f4da33cfb) Thanks [@drwpow](https://github.com/drwpow)! - Add RequestBodyJSON helper
- [#1458](https://github.com/openapi-ts/openapi-typescript/pull/1458) [`23517a2`](https://github.com/openapi-ts/openapi-typescript/commit/23517a2c2ab94d49085391130cd7d11f4da33cfb) Thanks [@drwpow](https://github.com/drwpow)! - Add RequestBodyJSON helper

@@ -30,3 +37,3 @@ ## 0.0.5

- [#1456](https://github.com/drwpow/openapi-typescript/pull/1456) [`5be2082`](https://github.com/drwpow/openapi-typescript/commit/5be20827334c60e53222445561b9cfc526f4f6a9) Thanks [@drwpow](https://github.com/drwpow)! - Add SuccessResponseJSON, ErrorResponseJSON helpers
- [#1456](https://github.com/openapi-ts/openapi-typescript/pull/1456) [`5be2082`](https://github.com/openapi-ts/openapi-typescript/commit/5be20827334c60e53222445561b9cfc526f4f6a9) Thanks [@drwpow](https://github.com/drwpow)! - Add SuccessResponseJSON, ErrorResponseJSON helpers

@@ -37,3 +44,3 @@ ## 0.0.4

- [#1366](https://github.com/drwpow/openapi-typescript/pull/1366) [`04dbd6d`](https://github.com/drwpow/openapi-typescript/commit/04dbd6d84fffd1d88300421bae25e946f1c303da) Thanks [@drwpow](https://github.com/drwpow)! - Add HasRequiredKeys<T> helper
- [#1366](https://github.com/openapi-ts/openapi-typescript/pull/1366) [`04dbd6d`](https://github.com/openapi-ts/openapi-typescript/commit/04dbd6d84fffd1d88300421bae25e946f1c303da) Thanks [@drwpow](https://github.com/drwpow)! - Add HasRequiredKeys<T> helper

@@ -44,3 +51,3 @@ ## 0.0.3

- [#1357](https://github.com/drwpow/openapi-typescript/pull/1357) [`996e51e`](https://github.com/drwpow/openapi-typescript/commit/996e51e9b475f4818af77301ed5c0ab458736cb9) Thanks [@muttonchop](https://github.com/muttonchop)! - adds 500-511 error status codes
- [#1357](https://github.com/openapi-ts/openapi-typescript/pull/1357) [`996e51e`](https://github.com/openapi-ts/openapi-typescript/commit/996e51e9b475f4818af77301ed5c0ab458736cb9) Thanks [@muttonchop](https://github.com/muttonchop)! - adds 500-511 error status codes

@@ -51,3 +58,3 @@ ## 0.0.2

- [#1326](https://github.com/drwpow/openapi-typescript/pull/1326) [`e63a345`](https://github.com/drwpow/openapi-typescript/commit/e63a34561c8137c4cfdef858a2272be32960ca4f) Thanks [@drwpow](https://github.com/drwpow)! - Fix type bug
- [#1326](https://github.com/openapi-ts/openapi-typescript/pull/1326) [`e63a345`](https://github.com/openapi-ts/openapi-typescript/commit/e63a34561c8137c4cfdef858a2272be32960ca4f) Thanks [@drwpow](https://github.com/drwpow)! - Fix type bug

@@ -54,0 +61,0 @@ ## 0.0.0

@@ -1,27 +0,72 @@

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
// HTTP types
export type HttpMethod =
| "get"
| "put"
| "post"
| "delete"
| "options"
| "head"
| "patch"
| "trace";
export type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
/** 2XX statuses */
export type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207 | "2XX";
// prettier-ignore
/** 4XX and 5XX statuses */
export type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | '5XX' | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 429 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | '4XX' | "default";
// biome-ignore format: keep on one line
export type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | '5XX' | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | '4XX' | "default";
/** Get a union of OK Statuses */
export type OKStatusUnion<T> = FilterKeys<T, OkStatus>;
/** Get first error status, in order */
// biome-ignore format: this is dumb but reliable
export type FirstErrorStatus<T> =
T extends { 500: any } ? T[500] :
T extends { 501: any } ? T[501] :
T extends { 502: any } ? T[502] :
T extends { 503: any } ? T[503] :
T extends { 504: any } ? T[504] :
T extends { 505: any } ? T[505] :
T extends { 506: any } ? T[506] :
T extends { 507: any } ? T[507] :
T extends { 508: any } ? T[508] :
T extends { 510: any } ? T[510] :
T extends { 511: any } ? T[511] :
T extends { "5XX": any } ? T["5XX"] :
T extends { 400: any } ? T[400] :
T extends { 401: any } ? T[401] :
T extends { 402: any } ? T[402] :
T extends { 403: any } ? T[403] :
T extends { 404: any } ? T[404] :
T extends { 405: any } ? T[405] :
T extends { 406: any } ? T[406] :
T extends { 407: any } ? T[407] :
T extends { 408: any } ? T[408] :
T extends { 409: any } ? T[409] :
T extends { 410: any } ? T[410] :
T extends { 411: any } ? T[411] :
T extends { 412: any } ? T[412] :
T extends { 413: any } ? T[413] :
T extends { 414: any } ? T[414] :
T extends { 415: any } ? T[415] :
T extends { 416: any } ? T[416] :
T extends { 417: any } ? T[417] :
T extends { 418: any } ? T[418] :
T extends { 420: any } ? T[420] :
T extends { 421: any } ? T[421] :
T extends { 422: any } ? T[422] :
T extends { 423: any } ? T[423] :
T extends { 424: any } ? T[424] :
T extends { 425: any } ? T[425] :
T extends { 426: any } ? T[426] :
T extends { 427: any } ? T[427] :
T extends { 428: any } ? T[428] :
T extends { 429: any } ? T[429] :
T extends { 430: any } ? T[430] :
T extends { 431: any } ? T[431] :
T extends { 444: any } ? T[444] :
T extends { 450: any } ? T[450] :
T extends { 451: any } ? T[451] :
T extends { 497: any } ? T[497] :
T extends { 498: any } ? T[498] :
T extends { 499: any } ? T[499] :
T extends { "4XX": any } ? T["4XX"] :
T extends { default: any } ? T["default"] : never;
// OpenAPI type helpers
/** Given an OpenAPI **Paths Object**, find all paths that have the given method */
export type PathsWithMethod<
Paths extends {},
PathnameMethod extends HttpMethod,
> = {
export type PathsWithMethod<Paths extends {}, PathnameMethod extends HttpMethod> = {
[Pathname in keyof Paths]: Paths[Pathname] extends {

@@ -33,3 +78,7 @@ [K in PathnameMethod]: any;

}[keyof Paths];
/** DO NOT USE! Only used only for OperationObject type inference */
/**
* DO NOT USE!
* Only used only for OperationObject type inference
*/
export interface OperationObject {

@@ -40,2 +89,3 @@ parameters: any;

}
/** Internal helper used in PathsWithMethod */

@@ -45,45 +95,44 @@ export type PathItemObject = {

} & { parameters?: any };
/** Return `responses` for an Operation Object */
export type ResponseObjectMap<T> = T extends { responses: any }
? T["responses"]
: unknown;
export type ResponseObjectMap<T> = T extends { responses: any } ? T["responses"] : unknown;
/** Return `content` for a Response Object */
export type ResponseContent<T> = T extends { content: any }
? T["content"]
: unknown;
export type ResponseContent<T> = T extends { content: any } ? T["content"] : unknown;
/** Return `requestBody` for an Operation Object */
export type OperationRequestBody<T> = T extends { requestBody?: any }
? T["requestBody"]
: never;
export type OperationRequestBody<T> = T extends { requestBody?: any } ? T["requestBody"] : never;
/** Internal helper used in OperationRequestBodyContent */
export type OperationRequestBodyMediaContent<T> =
undefined extends OperationRequestBody<T>
? FilterKeys<NonNullable<OperationRequestBody<T>>, "content"> | undefined
: FilterKeys<OperationRequestBody<T>, "content">;
export type OperationRequestBodyMediaContent<T> = undefined extends OperationRequestBody<T>
? ResponseContent<NonNullable<OperationRequestBody<T>>> | undefined
: ResponseContent<OperationRequestBody<T>>;
/** Return first `content` from a Request Object Mapping, allowing any media type */
export type OperationRequestBodyContent<T> =
FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never
?
| FilterKeys<
NonNullable<OperationRequestBodyMediaContent<T>>,
MediaType
>
| undefined
: FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
export type OperationRequestBodyContent<T> = FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never
? FilterKeys<NonNullable<OperationRequestBodyMediaContent<T>>, MediaType> | undefined
: FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
/** Return first 2XX response from a Response Object Map */
export type SuccessResponse<T> = ResponseContent<FilterKeys<T, OkStatus>>;
/** Return first 5XX or 4XX response (in that order) from a Response Object Map */
export type ErrorResponse<T> = ResponseContent<FilterKeys<T, ErrorStatus>>;
export type SuccessResponse<T, Media extends MediaType = MediaType> = FilterKeys<
ResponseContent<FilterKeys<T, OkStatus>>,
Media
>;
/**
* Return first 5XX or 4XX response (in that order) from a Response Object Map
*/
export type ErrorResponse<T, Media extends MediaType = MediaType> = FilterKeys<
ResponseContent<FirstErrorStatus<T>>,
Media
>;
/** Return first JSON-like 2XX response from a path + HTTP method */
export type SuccessResponseJSON<PathMethod> = JSONLike<
SuccessResponse<ResponseObjectMap<PathMethod>>
>;
export type SuccessResponseJSON<PathMethod> = JSONLike<SuccessResponse<ResponseObjectMap<PathMethod>>>;
/** Return first JSON-like 5XX or 4XX response from a path + HTTP method */
export type ErrorResponseJSON<PathMethod> = JSONLike<
ErrorResponse<ResponseObjectMap<PathMethod>>
>;
export type ErrorResponseJSON<PathMethod> = JSONLike<ErrorResponse<ResponseObjectMap<PathMethod>>>;
/** Return JSON-like request body from a path + HTTP method */
export type RequestBodyJSON<PathMethod> = JSONLike<
ResponseContent<OperationRequestBody<PathMethod>>
>;
export type RequestBodyJSON<PathMethod> = JSONLike<FilterKeys<OperationRequestBody<PathMethod>, "content">>;

@@ -94,4 +143,12 @@ // Generic TS utils

export type FilterKeys<Obj, Matchers> = Obj[keyof Obj & Matchers];
/** Get the type of a value of an input object with a given key. If the key is not found, return a default type. Works with unions of objects too. */
export type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends any ? (FilterKeys<Obj, KeyPattern> extends never ? Default : FilterKeys<Obj, KeyPattern>) : never;
/**
* @deprecated Use `FilterKeys` instead
* Get the type of a value of an input object with a given key. If the key is
* not found, return a default type. Works with unions of objects too.
*/
export type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends any
? FilterKeys<Obj, KeyPattern> extends never
? Default
: FilterKeys<Obj, KeyPattern>
: never;

@@ -103,8 +160,4 @@ /** Return any `[string]/[string]` media type (important because openapi-fetch allows any content response, not just JSON-like) */

/** Filter objects that have required keys */
export type FindRequiredKeys<T, K extends keyof T> = K extends unknown
? undefined extends T[K]
? never
: K
: K;
export type FindRequiredKeys<T, K extends keyof T> = K extends unknown ? (undefined extends T[K] ? never : K) : K;
/** Does this object contain required keys? */
export type HasRequiredKeys<T> = FindRequiredKeys<T, keyof T>;
{
"name": "openapi-typescript-helpers",
"description": "TypeScript helpers for consuming openapi-typescript types",
"version": "0.0.8",
"version": "0.0.9",
"author": {

@@ -26,21 +26,20 @@ "name": "Drew Powers",

},
"homepage": "https://openapi-ts.pages.dev",
"homepage": "https://openapi-ts.dev",
"repository": {
"type": "git",
"url": "https://github.com/drwpow/openapi-typescript",
"url": "https://github.com/openapi-ts/openapi-typescript",
"directory": "packages/openapi-fetch"
},
"bugs": {
"url": "https://github.com/drwpow/openapi-typescript/issues"
"url": "https://github.com/openapi-ts/openapi-typescript/issues"
},
"devDependencies": {
"typescript": "^5.4.5"
},
"scripts": {
"build": "cp index.d.ts index.d.cts",
"lint": "pnpm run lint:js",
"lint:js": "eslint \"*.{js,ts}\"",
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
"format": "biome format . --write",
"lint": "biome check .",
"test": "tsc --noEmit"
},
"devDependencies": {
"typescript": "^5.4.5"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc