8000 fix: Omit open API keys when generating client input params · aklinker1/zeta@97665aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 97665aa

Browse files
committed
fix: Omit open API keys when generating client input params
1 parent aa02ec0 commit 97665aa

3 files changed

Lines changed: 12 additions & 31 deletions

File tree

‎src/__tests__/client.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { expectTypeOf } from "expect-type";
77

88
describe("Client", () => {
99
describe("params", () => {
10-
it("should make apply named path params", async () => {
10+
it("should apply named path params correctly", async () => {
1111
const id = "one";
1212
const expectedPath = `/api/users/${id}`;
1313
const expectedParams = { id };
@@ -27,7 +27,7 @@ describe("Client", () => {
2727
expect(actual.params).toEqual(expectedParams);
2828
});
2929

30-
it("should make apply anonymous wildcard path params", async () => {
30+
it("should apply anonymous wildcard path params correctly", async () => {
3131
const id = "one";
3232
const expectedPath = `/api/users/${id}`;
3333
const expectedParams = { "**": id };
@@ -45,7 +45,7 @@ describe("Client", () => {
4545
expect(actual.params).toEqual(expectedParams);
4646
});
4747

48-
it("should make apply named wildcard path params", async () => {
48+
it("should apply named wildcard path params correctly", async () => {
4949
const id = "one";
5050
const expectedPath = `/api/users/${id}`;
5151
const expectedParams = { id };

‎src/__tests__/types.test.ts‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ describe("Types", () => {
128128
});
129129

130130
describe("GetRequestParamsInputFromDef", () => {
131-
it("should get input type for all fields, ignoring a single response", () => {
131+
it("should get input type for all fields, ignoring other fields on the definition", () => {
132132
type Def = {
133133
query: z.ZodObject<{ asc: z.ZodCoercedBoolean<string> }>;
134 8000 134
params: z.ZodObject<{ id: z.ZodString }>;
135135
body: z.ZodObject<{ id: z.ZodString; user: z.ZodString }>;
136+
operationId: string;
136137
responses: z.ZodArray<
137138
z.ZodObject<{ id: z.ZodString; user: z.ZodString }>
138139
>;
@@ -148,27 +149,6 @@ describe("Types", () => {
148149
expectTypeOf<Actual>().toEqualTypeOf<Expected>();
149150
});
150151

151-
it("should get input type for all fields, ignoring multiple responses", () => {
152-
type Def = {
153-
query: z.ZodObject<{ asc: z.ZodCoercedBoolean<string> }>;
154-
params: z.ZodObject<{ id: z.ZodString }>;
155-
body: z.ZodObject<{ id: z.ZodString; user: z.ZodString }>;
156-
responses: {
157-
200: z.ZodArray<z.ZodObject<{ id: z.ZodString; user: z.ZodString }>>;
158-
400: typeof ErrorResponse;
159-
};
160-
};
161-
type Expected = {
162-
query: { asc: string };
163-
params: { id: string };
164-
body: { id: string; user: string };
165-
};
166-
167-
type Actual = t.GetRequestParamsInputFromDef<Def>;
168-
169-
expectTypeOf<Actual>().toEqualTypeOf<Expected>();
170-
});
171-
172152
it("should include only the body", () => {
173153
type Def = {
174154
body: z.ZodObject<{ id: z.ZodString; user: z.ZodString }>;

‎src/types.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,7 @@ export type BuildHandlerContext<
751751
TPath extends BasePath,
752752
TRouteDef extends RouteDef,
753753
> = Simplify<
754-
Omit<
755-
OnBeforeHandleContext<GetAppDataCtx<TAppData>>,
756-
"body" | "query" | "params" | "headers"
757-
> & {
754+
Omit<OnBeforeHandleContext<GetAppDataCtx<TAppData>>, InputParams> & {
758755
route: TPath;
759756
} & GetRequestParamsOutputFromDef<TRouteDef> & {
760757
status: StatusFn<GetResponseStatusMap<TRouteDef>>;
@@ -972,10 +969,14 @@ export type GetResponseOutput<
972969
? GetResponseOutputFromDef<TRoutes[TMethod][TPath]>
973970
: never;
974971

972+
type InputParams = "headers" | "params" | "query" | "body";
973+
975974
/**
976-
* Given a route definition, return the same type minus the response.
975+
* Given a route definition, return an object with only the input parameeters.
977976
*/
978-
type GetDefParams<TRouteDef extends RouteDef> = Omit<TRouteDef, "responses">;
977+
type GetDefParams<TRouteDef extends RouteDef> = {
978+
[key in InputParams & keyof TRouteDef]: TRouteDef[key];
979+
};
979980

980981
//
981982
// SCHEMA ADAPTER

0 commit comments

Comments
 (0)
0