Skip to content

Commit d780a69

Browse files
authored
Merge pull request #2344 from Daschi1/issue-2194
2 parents 08f219e + fb7b724 commit d780a69

File tree

29 files changed

+2928
-74
lines changed

29 files changed

+2928
-74
lines changed

.changeset/stale-starfishes-sell.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+
fix(valibot): expand support for `format: int64`

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,15 @@ describe(`OpenAPI ${version}`, () => {
798798
}),
799799
description: "validator schemas with merged unions (can't use .merge())",
800800
},
801+
{
802+
config: createConfig({
803+
input: 'integer-formats.yaml',
804+
output: 'integer-formats',
805+
plugins: ['valibot'],
806+
}),
807+
description:
808+
'generates validator schemas for all integer format combinations (number/integer/string types with int8, int16, int32, int64, uint8, uint16, uint32, uint64 formats)',
809+
},
801810
];
802811

803812
it.each(scenarios)('$description', async ({ config }) => {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.optional(v.bigint(), BigInt(0)),
7+
foo: v.optional(v.pipe(v.union([
8+
v.number(),
9+
v.string(),
10+
v.bigint()
11+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)),
812
id: v.string()
913
});
1014

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ export const vCollectionFormatData = v.object({
664664
export const vTypesData = v.object({
665665
body: v.optional(v.never()),
666666
path: v.optional(v.object({
667-
id: v.optional(v.pipe(v.number(), v.integer()))
667+
id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')))
668668
})),
669669
query: v.object({
670670
parameterNumber: v.optional(v.number(), 123),

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.optional(v.bigint(), BigInt(0)),
7+
foo: v.optional(v.pipe(v.union([
8+
v.number(),
9+
v.string(),
10+
v.bigint()
11+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)),
812
id: v.string()
913
});
1014

packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ export const vDefault = v.object({
714714
});
715715

716716
export const vPageable = v.object({
717-
page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 0),
718-
size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
717+
page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(0)), 0),
718+
size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(1))),
719719
sort: v.optional(v.array(v.string()))
720720
});
721721

@@ -775,10 +775,10 @@ export const vCompositionWithOneOfAndProperties = v.intersect([
775775
]),
776776
v.object({
777777
baz: v.union([
778-
v.pipe(v.number(), v.integer(), v.minValue(0)),
778+
v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)),
779779
v.null()
780780
]),
781-
qux: v.pipe(v.number(), v.integer(), v.minValue(0))
781+
qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0))
782782
})
783783
]);
784784

@@ -943,10 +943,10 @@ export const vModelWithOneOfAndProperties = v.intersect([
943943
]),
944944
v.object({
945945
baz: v.union([
946-
v.pipe(v.number(), v.integer(), v.minValue(0)),
946+
v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)),
947947
v.null()
948948
]),
949-
qux: v.pipe(v.number(), v.integer(), v.minValue(0))
949+
qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0))
950950
})
951951
]);
952952

@@ -1812,7 +1812,7 @@ export const vCollectionFormatData = v.object({
18121812
export const vTypesData = v.object({
18131813
body: v.optional(v.never()),
18141814
path: v.optional(v.object({
1815-
id: v.optional(v.pipe(v.number(), v.integer()))
1815+
id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')))
18161816
})),
18171817
query: v.object({
18181818
parameterNumber: v.optional(v.number(), 123),
@@ -1958,15 +1958,15 @@ export const vComplexParamsData = v.object({
19581958
vModelWithDictionary
19591959
]),
19601960
user: v.optional(v.pipe(v.object({
1961-
id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())),
1961+
id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), v.readonly())),
19621962
name: v.optional(v.pipe(v.union([
19631963
v.pipe(v.string(), v.readonly()),
19641964
v.null()
19651965
]), v.readonly()))
19661966
}), v.readonly()))
19671967
})),
19681968
path: v.object({
1969-
id: v.pipe(v.number(), v.integer()),
1969+
id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')),
19701970
'api-version': v.string()
19711971
}),
19721972
query: v.optional(v.never())
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as v from 'valibot';
4+
5+
export const vIntegerFormats = v.object({
6+
numberNoFormat: v.optional(v.number()),
7+
numberInt8: v.optional(v.pipe(v.number(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -2^7'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 2^7-1'))),
8+
numberInt16: v.optional(v.pipe(v.number(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -2^15'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 2^15-1'))),
9+
numberInt32: v.optional(v.pipe(v.number(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))),
10+
numberInt64: v.optional(v.pipe(v.union([
11+
v.number(),
12+
v.string(),
13+
v.bigint()
14+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))),
15+
numberUint8: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'))),
16+
numberUint16: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'))),
17+
numberUint32: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 2^32-1'))),
18+
numberUint64: v.optional(v.pipe(v.union([
19+
v.number(),
20+
v.string(),
21+
v.bigint()
22+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1'))),
23+
integerNoFormat: v.optional(v.pipe(v.number(), v.integer())),
24+
integerInt8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -2^7'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 2^7-1'))),
25+
integerInt16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -2^15'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 2^15-1'))),
26+
integerInt32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))),
27+
integerInt64: v.optional(v.pipe(v.union([
28+
v.number(),
29+
v.string(),
30+
v.bigint()
31+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))),
32+
integerUint8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'))),
33+
integerUint16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'))),
34+
integerUint32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 2^32-1'))),
35+
integerUint64: v.optional(v.pipe(v.union([
36+
v.number(),
37+
v.string(),
38+
v.bigint()
39+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1'))),
40+
stringInt64: v.optional(v.pipe(v.union([
41+
v.number(),
42+
v.string(),
43+
v.bigint()
44+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))),
45+
stringUint64: v.optional(v.pipe(v.union([
46+
v.number(),
47+
v.string(),
48+
v.bigint()
49+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1')))
50+
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.optional(v.bigint(), BigInt(0)),
7+
foo: v.optional(v.pipe(v.union([
8+
v.number(),
9+
v.string(),
10+
v.bigint()
11+
]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)),
812
id: v.string()
913
});
1014

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ export const vDefault = v.object({
709709
});
710710

711711
export const vPageable = v.object({
712-
page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 0),
713-
size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
712+
page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(0)), 0),
713+
size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(1))),
714714
sort: v.optional(v.array(v.string()))
715715
});
716716

@@ -766,10 +766,10 @@ export const vCompositionWithOneOfAndProperties = v.intersect([
766766
]),
767767
v.object({
768768
baz: v.union([
769-
v.pipe(v.number(), v.integer(), v.minValue(0)),
769+
v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)),
770770
v.null()
771771
]),
772-
qux: v.pipe(v.number(), v.integer(), v.minValue(0))
772+
qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0))
773773
})
774774
]);
775775

@@ -941,10 +941,10 @@ export const vModelWithOneOfAndProperties = v.intersect([
941941
]),
942942
v.object({
943943
baz: v.union([
944-
v.pipe(v.number(), v.integer(), v.minValue(0)),
944+
v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)),
945945
v.null()
946946
]),
947-
qux: v.pipe(v.number(), v.integer(), v.minValue(0))
947+
qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0))
948948
})
949949
]);
950950

@@ -1817,7 +1817,7 @@ export const vCollectionFormatData = v.object({
18171817
export const vTypesData = v.object({
18181818
body: v.optional(v.never()),
18191819
path: v.optional(v.object({
1820-
id: v.optional(v.pipe(v.number(), v.integer()))
1820+
id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')))
18211821
})),
18221822
query: v.object({
18231823
parameterNumber: v.optional(v.number(), 123),
@@ -1964,15 +1964,15 @@ export const vComplexParamsData = v.object({
19641964
vModelWithDictionary
19651965
]),
19661966
user: v.optional(v.pipe(v.object({
1967-
id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())),
1967+
id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), v.readonly())),
19681968
name: v.optional(v.pipe(v.union([
19691969
v.pipe(v.string(), v.readonly()),
19701970
v.null()
19711971
]), v.readonly()))
19721972
}), v.readonly()))
19731973
})),
19741974
path: v.object({
1975-
id: v.pipe(v.number(), v.integer()),
1975+
id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')),
19761976
'api-version': v.string()
19771977
}),
19781978
query: v.optional(v.never())

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/types.gen.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ export type Foo = {
1616
[key: string]: unknown;
1717
};
1818
garply?: 10n;
19+
numberInt8?: 100;
20+
numberInt16?: 1000;
21+
numberInt32?: 100000;
22+
numberInt64?: 1000000000000;
23+
numberUint8?: 200;
24+
numberUint16?: 50000;
25+
numberUint32?: 3000000000;
26+
numberUint64?: 18000000000000000000;
27+
integerInt8?: -100;
28+
integerInt16?: -1000;
29+
integerInt32?: -100000;
30+
integerInt64?: -1000000000000;
31+
integerUint8?: 255;
32+
integerUint16?: 65535;
33+
integerUint32?: 4294967295;
34+
integerUint64?: 18446744073709551615n;
35+
stringInt64?: '-9223372036854775808';
36+
stringUint64?: '18446744073709551615';
1937
};
2038

2139
export type ClientOptions = {

0 commit comments

Comments
 (0)