Skip to content

Commit 4faf1dd

Browse files
fix: tests xd
1 parent 2d80604 commit 4faf1dd

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

packages/orval/src/write-zod-specs.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ describe('write-zod-specs regressions', () => {
273273
zod: {
274274
...createOutputOptions().override.zod,
275275
generate: {
276+
param: true,
276277
body: true,
277278
query: true,
278279
header: true,

packages/orval/src/write-zod-specs.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'node:path';
33
import {
44
type ContextSpec,
55
conventionName,
6-
type GeneratorVerbOptions,
76
type NamingConvention,
87
type NormalizedOutputOptions,
98
type OpenApiParameterObject,
@@ -42,6 +41,13 @@ interface WriteZodOutputOptions {
4241
strict: {
4342
body: boolean;
4443
};
44+
generate: {
45+
param: boolean;
46+
query: boolean;
47+
header: boolean;
48+
body: boolean;
49+
response: boolean;
50+
};
4551
coerce: {
4652
body: boolean | ZodCoerceType[];
4753
};
@@ -64,12 +70,28 @@ interface WriteZodVerbResponseType {
6470
originalSchema?: OpenApiSchemaObject;
6571
}
6672

73+
interface WriteZodSchemasFromVerbsEntry {
74+
operationName: string;
75+
originalOperation: {
76+
requestBody?: OpenApiRequestBodyObject | OpenApiReferenceObject;
77+
parameters?: (OpenApiParameterObject | OpenApiReferenceObject)[];
78+
};
79+
response: {
80+
types: {
81+
success: WriteZodVerbResponseType[];
82+
errors: WriteZodVerbResponseType[];
83+
};
84+
};
85+
override?: {
86+
zod: {
87+
generate: WriteZodOutputOptions['override']['zod']['generate'];
88+
};
89+
};
90+
}
91+
6792
type WriteZodSchemasFromVerbsInput = Record<
6893
string,
69-
Pick<
70-
GeneratorVerbOptions,
71-
'operationName' | 'originalOperation' | 'response' | 'override'
72-
>
94+
WriteZodSchemasFromVerbsEntry
7395
>;
7496

7597
interface WriteZodSchemasFromVerbsContext {

packages/zod/src/zod.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,9 @@ describe('generatePartOfSchemaGenerateZod', () => {
35263526
});
35273527

35283528
it('falls back to 2XX response when 200 is not present', async () => {
3529+
const basePostOperation =
3530+
basicApiSchema.context.spec.paths?.['/cats']?.post ?? {};
3531+
35293532
const wildcardResponseApiSchema = {
35303533
...basicApiSchema,
35313534
context: {
@@ -3535,7 +3538,7 @@ describe('generatePartOfSchemaGenerateZod', () => {
35353538
paths: {
35363539
'/cats': {
35373540
post: {
3538-
...basicApiSchema.context.spec.paths['/cats'].post,
3541+
...basePostOperation,
35393542
responses: {
35403543
'2XX': {
35413544
content: {

0 commit comments

Comments
 (0)