Skip to content

Commit 06fe0ff

Browse files
committed
test(zod): add snapshot tests for binary format and contentMediaType
- Add two new test scenarios to 3.1.x.test.ts: - content-binary.json + zod: verifies z.instanceof(Blob/File) for format: binary - content-media-type.yaml + zod: verifies z.instanceof(Blob/File) for contentMediaType - Add content-media-type.yaml spec (backport from merged PR #3431) - Apply parser fix for contentMediaType → binary format inference (backport from #3431) - Update string-with-format zod snapshot to reflect corrected binary output Snapshots confirm: z.union([z.instanceof(Blob), z.instanceof(File)]) for all binary fields
1 parent 9429b37 commit 06fe0ff

8 files changed

Lines changed: 145 additions & 1 deletion

File tree

packages/openapi-ts-tests/main/test/3.1.x.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ describe(`OpenAPI ${version}`, () => {
199199
}),
200200
description: 'handles contentMediaType schema property for file uploads',
201201
},
202+
{
203+
config: createConfig({
204+
input: 'content-binary.json',
205+
output: 'content-binary-zod',
206+
plugins: ['@hey-api/typescript', 'zod'],
207+
}),
208+
description:
209+
'generates z.instanceof(Blob/File) for binary format with zod',
210+
},
211+
{
212+
config: createConfig({
213+
input: 'content-media-type.yaml',
214+
output: 'content-media-type-zod',
215+
plugins: ['@hey-api/typescript', 'zod'],
216+
}),
217+
description:
218+
'generates z.instanceof(Blob/File) for contentMediaType with zod',
219+
},
202220
{
203221
config: createConfig({
204222
input: 'content-types.yaml',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type { ClientOptions, GetBarData, GetBarResponse, GetBarResponses, GetFooData, GetFooResponse, GetFooResponses } from './types.gen';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type ClientOptions = {
4+
baseUrl: `${string}://${string}` | (string & {});
5+
};
6+
7+
export type GetFooData = {
8+
body?: never;
9+
path?: never;
10+
query?: never;
11+
url: '/foo';
12+
};
13+
14+
export type GetFooResponses = {
15+
200: string;
16+
};
17+
18+
export type GetFooResponse = GetFooResponses[keyof GetFooResponses];
19+
20+
export type GetBarData = {
21+
body?: never;
22+
path?: never;
23+
query?: never;
24+
url: '/bar';
25+
};
26+
27+
export type GetBarResponses = {
28+
200: Blob | File;
29+
};
30+
31+
export type GetBarResponse = GetBarResponses[keyof GetBarResponses];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod';
4+
5+
export const zGetFooData = z.object({
6+
body: z.optional(z.never()),
7+
path: z.optional(z.never()),
8+
query: z.optional(z.never())
9+
});
10+
11+
export const zGetFooResponse = z.string();
12+
13+
export const zGetBarData = z.object({
14+
body: z.optional(z.never()),
15+
path: z.optional(z.never()),
16+
query: z.optional(z.never())
17+
});
18+
19+
export const zGetBarResponse = z.union([z.instanceof(Blob), z.instanceof(File)]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type { ClientOptions, FileUploadRequest, FileUploadRequestTyped, UploadFileData, UploadFileResponses, UploadFileTypedData, UploadFileTypedResponses } from './types.gen';
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type ClientOptions = {
4+
baseUrl: `${string}://${string}` | (string & {});
5+
};
6+
7+
export type FileUploadRequest = {
8+
/**
9+
* Binary file content
10+
*/
11+
file: Blob | File;
12+
};
13+
14+
export type FileUploadRequestTyped = {
15+
/**
16+
* Binary file content with explicit string type
17+
*/
18+
file: Blob | File;
19+
};
20+
21+
export type UploadFileData = {
22+
body?: FileUploadRequest;
23+
path?: never;
24+
query?: never;
25+
url: '/upload';
26+
};
27+
28+
export type UploadFileResponses = {
29+
/**
30+
* OK
31+
*/
32+
200: unknown;
33+
};
34+
35+
export type UploadFileTypedData = {
36+
body?: FileUploadRequestTyped;
37+
path?: never;
38+
query?: never;
39+
url: '/upload-typed';
40+
};
41+
42+
export type UploadFileTypedResponses = {
43+
/**
44+
* OK
45+
*/
46+
200: unknown;
47+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod';
4+
5+
export const zFileUploadRequest = z.object({
6+
file: z.union([z.instanceof(Blob), z.instanceof(File)])
7+
});
8+
9+
export const zFileUploadRequestTyped = z.object({
10+
file: z.union([z.instanceof(Blob), z.instanceof(File)])
11+
});
12+
13+
export const zUploadFileData = z.object({
14+
body: z.optional(zFileUploadRequest),
15+
path: z.optional(z.never()),
16+
query: z.optional(z.never())
17+
});
18+
19+
export const zUploadFileTypedData = z.object({
20+
body: z.optional(zFileUploadRequestTyped),
21+
path: z.optional(z.never()),
22+
query: z.optional(z.never())
23+
});

packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/string-with-format/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import * as z from 'zod/mini';
44

55
export const zFoo = z.object({
6-
foo: z.optional(z.array(z.union([z.string(), z.string()])))
6+
foo: z.optional(z.array(z.union([z.union([z.instanceof(Blob), z.instanceof(File)]), z.string()])))
77
});

0 commit comments

Comments
 (0)