From 45454f217866308a2aae6e36fde8cfb79e48312c Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Mon, 18 Sep 2023 18:34:14 -0400 Subject: [PATCH 1/4] fix: clean up the exported types Signed-off-by: Aramis Sennyey --- packages/backend-openapi-utils/README.md | 6 + packages/backend-openapi-utils/api-report.md | 125 ++++++++++-------- .../backend-openapi-utils/src/stub.test.ts | 14 +- .../backend-openapi-utils/src/types/common.ts | 45 ++++--- .../src/types/express.ts | 41 ++++-- .../backend-openapi-utils/src/types/params.ts | 23 ++-- .../src/types/requests.ts | 14 +- .../src/types/responses.ts | 11 +- packages/backend-openapi-utils/src/utility.ts | 81 ++++++++++++ .../request/parseQueryEntitiesParams.ts | 4 +- 10 files changed, 250 insertions(+), 114 deletions(-) create mode 100644 packages/backend-openapi-utils/src/utility.ts diff --git a/packages/backend-openapi-utils/README.md b/packages/backend-openapi-utils/README.md index 1efab0e85b..ca3f03fcc1 100644 --- a/packages/backend-openapi-utils/README.md +++ b/packages/backend-openapi-utils/README.md @@ -61,6 +61,12 @@ export function createRouter() { } ``` +## FAQs + +### Why am I getting `unknown` as the type for a response? + +This can happen when you have a `charset` defined in your `response.content` section. Something like `response.content[ 'application/json; charset=utf-8:']` will cause this issue. + ## INTERNAL ### Limitations diff --git a/packages/backend-openapi-utils/api-report.md b/packages/backend-openapi-utils/api-report.md index 08ffa23a30..26215ad2a5 100644 --- a/packages/backend-openapi-utils/api-report.md +++ b/packages/backend-openapi-utils/api-report.md @@ -77,9 +77,9 @@ interface CookieObject extends ParameterObject { // @public (undocumented) type CookieSchema< Doc extends RequiredDoc, - Path extends PathTemplate>, + Path extends DocPath, Method extends DocPathMethod, -> = ParametersSchema, Method, ImmutableCookieObject>; +> = ParametersSchema; // @public export function createValidatedOpenApiRouter( @@ -99,16 +99,16 @@ type DiscriminateUnion = Extract< // @public (undocumented) type DocOperation< Doc extends RequiredDoc, - Path extends keyof Doc['paths'], + Path extends DocPath, Method extends keyof Doc['paths'][Path], > = Doc['paths'][Path][Method]; // @public (undocumented) type DocParameter< Doc extends RequiredDoc, - Path extends Extract, - Method extends keyof Doc['paths'][Path], - Parameter extends keyof Doc['paths'][Path][Method]['parameters'], + Path extends DocPath, + Method extends DocPathMethod, + Parameter extends keyof DocOperation['parameters'], > = DocOperation< Doc, Path, @@ -142,32 +142,28 @@ type DocParameters< }; // @public -type DocPath< - Doc extends PathDoc, - Path extends PathTemplate>, -> = ValueOf<{ - [Template in Extract< - keyof Doc['paths'], - string - >]: Path extends PathTemplate