Skip to content

Commit

Permalink
okay, I think this will fix #918 for realz
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed May 30, 2024
1 parent 645d6a3 commit 0bcf083
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-crabs-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": minor
---

fix argument type for .json() (third time's a charm?)
19 changes: 15 additions & 4 deletions src/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ type IfHasKey<SomeObject, Keys extends (keyof any)[], Yes, No> = Keys extends [
: No
: No;

type SchemasOf<T extends { [key: string]: { schema: any } }> = {
[K in keyof T]: T[K]["schema"];
}[keyof T];

type MaybeShortcut<
ContentTypes extends MediaType[],
Response extends OpenApiResponse,
> = IfHasKey<
Response["content"],
ContentTypes,
(
body: Response["content"][ArrayToUnion<ContentTypes>]["schema"],
) => GenericResponseBuilder<{
(body: SchemasOf<Response["content"]>) => GenericResponseBuilder<{
content: NeverIfEmpty<OmitAll<Response["content"], ContentTypes>>;
headers: Response["headers"];
requiredHeaders: Response["requiredHeaders"];
Expand Down Expand Up @@ -114,7 +116,16 @@ type GenericResponseBuilderInner<
? never
: HeaderFunction<Response>;
html: MaybeShortcut<["text/html"], Response>;
json: MaybeShortcut<["application/json", "text/json", "text/x-json", "application/xml", "text/xml"], Response>;
json: MaybeShortcut<
[
"application/json",
"text/json",
"text/x-json",
"application/xml",
"text/xml",
],
Response
>;
match: [keyof Response["content"]] extends [never]
? never
: MatchFunction<Response>;
Expand Down

0 comments on commit 0bcf083

Please sign in to comment.