Skip to content

Commit bb53a98

Browse files
authored
Merge pull request #3398 from hey-api/refactor/zod-plugin-nullish
refactor: zod plugin nullish
2 parents af099f3 + 737730c commit bb53a98

175 files changed

Lines changed: 5385 additions & 7403 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/ninety-towns-act.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@hey-api/openapi-ts": minor
3+
---
4+
5+
**plugin(zod)**: remove `enum.nodes.nullable` resolver node
6+
7+
### Removed resolver node
8+
9+
Zod plugin no longer exposes the `enum.nodes.nullable` node. It was refactored so that nullable values are handled outside of resolvers.

.changeset/proud-trains-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(zod)**: use `.nullable()` and `.nullish()` methods

dev/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { getSpecsPath } from '../packages/openapi-ts-tests/utils';
44

55
export const inputs = {
6-
circular: path.resolve(getSpecsPath(), '3.1.x', 'circular.yaml'),
6+
circular: path.resolve(getSpecsPath(), '3.0.x', 'circular.yaml'),
77
full: path.resolve(getSpecsPath(), '3.1.x', 'full.yaml'),
88
local: 'http://localhost:8000/openapi.json',
99
opencode: path.resolve(getSpecsPath(), '3.1.x', 'opencode.yaml'),

dev/python/plugins.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import type { UserConfig } from '@hey-api/openapi-python';
33
type PluginConfig = NonNullable<NonNullable<UserConfig['plugins']>[number]>;
44

55
export function sdk(
6-
options?: Partial<Omit<Extract<PluginConfig, { name: '@hey-api/python-sdk' }>, 'name'>>,
7-
) {
6+
options?: Omit<Extract<PluginConfig, { name: '@hey-api/python-sdk' }>, 'name'>,
7+
): Extract<PluginConfig, { name: '@hey-api/python-sdk' }> {
88
return {
99
name: '@hey-api/python-sdk' as const,
1010
...options,
1111
};
1212
}
1313

1414
export function pydantic(
15-
options?: Partial<Omit<Extract<PluginConfig, { name: 'pydantic' }>, 'name'>>,
16-
) {
15+
options?: Omit<Extract<PluginConfig, { name: 'pydantic' }>, 'name'>,
16+
): Extract<PluginConfig, { name: 'pydantic' }> {
1717
return {
1818
name: 'pydantic' as const,
1919
...options,

dev/typescript/plugins.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,53 @@ import type { UserConfig } from '@hey-api/openapi-ts';
33
type PluginConfig = NonNullable<NonNullable<UserConfig['plugins']>[number]>;
44

55
export function typescript(
6-
options?: Partial<Omit<Extract<PluginConfig, { name: '@hey-api/typescript' }>, 'name'>>,
7-
) {
6+
options?: Omit<Extract<PluginConfig, { name: '@hey-api/typescript' }>, 'name'>,
7+
): Extract<PluginConfig, { name: '@hey-api/typescript' }> {
88
return {
99
name: '@hey-api/typescript' as const,
1010
...options,
1111
};
1212
}
1313

1414
export function sdk(
15-
options?: Partial<Omit<Extract<PluginConfig, { name: '@hey-api/sdk' }>, 'name'>>,
16-
) {
15+
options?: Omit<Extract<PluginConfig, { name: '@hey-api/sdk' }>, 'name'>,
16+
): Extract<PluginConfig, { name: '@hey-api/sdk' }> {
1717
return {
1818
name: '@hey-api/sdk' as const,
1919
...options,
2020
};
2121
}
2222

23-
export function zod(options?: Partial<Omit<Extract<PluginConfig, { name: 'zod' }>, 'name'>>) {
23+
export function zod(
24+
options?: Omit<Extract<PluginConfig, { name: 'zod' }>, 'name'>,
25+
): Extract<PluginConfig, { name: 'zod' }> {
2426
return {
2527
name: 'zod' as const,
2628
...options,
2729
};
2830
}
2931

3032
export function valibot(
31-
options?: Partial<Omit<Extract<PluginConfig, { name: 'valibot' }>, 'name'>>,
32-
) {
33+
options?: Omit<Extract<PluginConfig, { name: 'valibot' }>, 'name'>,
34+
): Extract<PluginConfig, { name: 'valibot' }> {
3335
return {
3436
name: 'valibot' as const,
3537
...options,
3638
};
3739
}
3840

3941
export function tanstackReactQuery(
40-
options?: Partial<Omit<Extract<PluginConfig, { name: '@tanstack/react-query' }>, 'name'>>,
41-
) {
42+
options?: Omit<Extract<PluginConfig, { name: '@tanstack/react-query' }>, 'name'>,
43+
): Extract<PluginConfig, { name: '@tanstack/react-query' }> {
4244
return {
4345
name: '@tanstack/react-query' as const,
4446
...options,
4547
};
4648
}
4749

4850
export function transformers(
49-
options?: Partial<Omit<Extract<PluginConfig, { name: '@hey-api/transformers' }>, 'name'>>,
50-
) {
51+
options?: Omit<Extract<PluginConfig, { name: '@hey-api/transformers' }>, 'name'>,
52+
): Extract<PluginConfig, { name: '@hey-api/transformers' }> {
5153
return {
5254
name: '@hey-api/transformers' as const,
5355
...options,

packages/openapi-python/src/plugins/pydantic/v2/toAst/string.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { SchemaWithType } from '@hey-api/shared';
33
// import { $ } from '../../../../py-dsl';
44
import type { Ast, IrSchemaToAstOptions } from '../../shared/types';
55

6-
export const stringToNode = ({
6+
export function stringToNode({
77
schema,
88
}: IrSchemaToAstOptions & {
99
schema: SchemaWithType<'string'>;
10-
}): Ast => {
10+
}): Ast {
1111
const constraints: Record<string, unknown> = {};
1212

1313
if (schema.minLength !== undefined) {
@@ -45,4 +45,4 @@ export const stringToNode = ({
4545
// pipes: [],
4646
typeAnnotation: 'str',
4747
};
48-
};
48+
}

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as z from 'zod';
44

55
export const zFoo = z.object({
6-
bar: z.optional(z.int()),
6+
bar: z.int().optional(),
77
foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)),
88
id: z.string()
99
});
@@ -13,9 +13,9 @@ export const zBar = z.object({
1313
});
1414

1515
export const zPostFooData = z.object({
16-
body: z.optional(z.never()),
17-
path: z.optional(z.never()),
18-
query: z.optional(z.never())
16+
body: z.never().optional(),
17+
path: z.never().optional(),
18+
query: z.never().optional()
1919
});
2020

2121
/**

packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as z from 'zod';
44

55
export const zFoo = z.object({
6-
bar: z.optional(z.int()),
6+
bar: z.int().optional(),
77
foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)),
88
id: z.string()
99
});
@@ -13,9 +13,9 @@ export const zBar = z.object({
1313
});
1414

1515
export const zPostFooData = z.object({
16-
body: z.optional(z.never()),
17-
path: z.optional(z.never()),
18-
query: z.optional(z.never())
16+
body: z.never().optional(),
17+
path: z.never().optional(),
18+
query: z.never().optional()
1919
});
2020

2121
/**

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as z from 'zod';
44

55
export const zFoo = z.object({
6-
bar: z.optional(z.int()),
6+
bar: z.int().optional(),
77
foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)),
88
id: z.string()
99
});
@@ -13,9 +13,9 @@ export const zBar = z.object({
1313
});
1414

1515
export const zPostFooData = z.object({
16-
body: z.optional(z.never()),
17-
path: z.optional(z.never()),
18-
query: z.optional(z.never())
16+
body: z.never().optional(),
17+
path: z.never().optional(),
18+
query: z.never().optional()
1919
});
2020

2121
/**

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/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';
44

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

0 commit comments

Comments
 (0)