Skip to content

Commit 4fb0e1b

Browse files
authored
Merge pull request #2630 from hey-api/fix/anyof-string-binary
fix(typescript): handle string and binary string in composite keywords
2 parents 6e0f060 + 43a0661 commit 4fb0e1b

File tree

32 files changed

+478
-403
lines changed

32 files changed

+478
-403
lines changed

.changeset/purple-elephants-lie.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(typescript): handle string and binary string in composite keywords

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,14 @@ describe(`OpenAPI ${version}`, () => {
941941
}),
942942
description: 'webhook types and validator schemas',
943943
},
944+
{
945+
config: createConfig({
946+
input: 'string-with-format.yaml',
947+
output: 'string-with-format',
948+
plugins: ['@hey-api/typescript', 'valibot', 'zod'],
949+
}),
950+
description: 'anyOf string and binary string',
951+
},
944952
];
945953

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

packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pattern-properties/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type UnionPatternObject = {
2727
[key: string]: unknown;
2828
} & {
2929
level?: number;
30-
}) | (string | number) | ('user' | 'admin' | 'guest') | undefined;
30+
}) | string | number | 'user' | 'admin' | 'guest' | undefined;
3131
};
3232

3333
export type PatternPropertiesResponse = {
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 * from './types.gen';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type Foo = {
4+
foo?: Array<Blob | File | string>;
5+
};
6+
7+
export type ClientOptions = {
8+
baseUrl: `${string}://${string}` | (string & {});
9+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as v from 'valibot';
4+
5+
export const vFoo = v.object({
6+
foo: v.optional(v.array(v.unknown()))
7+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { z } from 'zod';
4+
5+
export const zFoo = z.object({
6+
foo: z.optional(z.array(z.union([
7+
z.string(),
8+
z.string()
9+
])))
10+
});

packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v2/types.gen.ts.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export type ArrayWithArray = Array<Array<ModelWithString>>;
1212
/**
1313
* This is a simple array with booleans
1414
*/
15-
export type ArrayWithBooleans = Array<(boolean)>;
15+
export type ArrayWithBooleans = Array<boolean>;
1616

1717
/**
1818
* This is a simple array with numbers
1919
*/
20-
export type ArrayWithNumbers = Array<(number)>;
20+
export type ArrayWithNumbers = Array<number>;
2121

2222
/**
2323
* This is a simple array with properties
@@ -35,7 +35,7 @@ export type ArrayWithReferences = Array<ModelWithString>;
3535
/**
3636
* This is a simple array with strings
3737
*/
38-
export type ArrayWithStrings = Array<(string)>;
38+
export type ArrayWithStrings = Array<string>;
3939

4040
/**
4141
* Testing backticks in string: `backticks` and ```multiple backticks``` should work
@@ -92,7 +92,7 @@ export type DictionaryWithArray = {
9292
*/
9393
export type DictionaryWithDictionary = {
9494
[key: string]: {
95-
[key: string]: (string);
95+
[key: string]: string;
9696
};
9797
};
9898

@@ -117,7 +117,7 @@ export type DictionaryWithReference = {
117117
* This is a string dictionary
118118
*/
119119
export type DictionaryWithString = {
120-
[key: string]: (string);
120+
[key: string]: string;
121121
};
122122

123123
/**
@@ -218,8 +218,8 @@ export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & {
218218
*/
219219
export type ModelWithArray = {
220220
prop?: Array<ModelWithString>;
221-
propWithFile?: Array<((Blob | File))>;
222-
propWithNumber?: Array<(number)>;
221+
propWithFile?: Array<Blob | File>;
222+
propWithNumber?: Array<number>;
223223
};
224224

225225
/**
@@ -244,7 +244,7 @@ export type ModelWithCircularReference = {
244244
*/
245245
export type ModelWithDictionary = {
246246
prop?: {
247-
[key: string]: (string);
247+
[key: string]: string;
248248
};
249249
};
250250

@@ -330,13 +330,13 @@ export type ModelWithInteger = {
330330
*/
331331
export type ModelWithNestedEnums = {
332332
dictionaryWithEnum?: {
333-
[key: string]: ('Success' | 'Warning' | 'Error');
333+
[key: string]: 'Success' | 'Warning' | 'Error';
334334
};
335335
dictionaryWithEnumFromDescription?: {
336-
[key: string]: (number);
336+
[key: string]: number;
337337
};
338-
arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>;
339-
arrayWithDescription?: Array<(number)>;
338+
arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>;
339+
arrayWithDescription?: Array<number>;
340340
};
341341

342342
/**
@@ -461,7 +461,7 @@ export type SimpleBoolean = boolean;
461461
/**
462462
* This is a simple file
463463
*/
464-
export type SimpleFile = (Blob | File);
464+
export type SimpleFile = Blob | File;
465465

466466
/**
467467
* This is a simple number

packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v3/types.gen.ts.snap

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type _import = string;
2323

2424
export type AdditionalPropertiesIntegerIssue = {
2525
value: number;
26-
[key: string]: (number) | undefined;
26+
[key: string]: number | undefined;
2727
};
2828

2929
export type AdditionalPropertiesUnknownIssue = {
@@ -72,12 +72,12 @@ export type ArrayWithArray = Array<Array<ModelWithString>>;
7272
/**
7373
* This is a simple array with booleans
7474
*/
75-
export type ArrayWithBooleans = Array<(boolean)>;
75+
export type ArrayWithBooleans = Array<boolean>;
7676

7777
/**
7878
* This is a simple array with numbers
7979
*/
80-
export type ArrayWithNumbers = Array<(number)>;
80+
export type ArrayWithNumbers = Array<number>;
8181

8282
/**
8383
* This is a simple array with properties
@@ -95,7 +95,7 @@ export type ArrayWithReferences = Array<ModelWithString>;
9595
/**
9696
* This is a simple array with strings
9797
*/
98-
export type ArrayWithStrings = Array<(string)>;
98+
export type ArrayWithStrings = Array<string>;
9999

100100
/**
101101
* Testing multiline comments in string: First line
@@ -252,7 +252,7 @@ export type CompositionWithOneOfAndProperties = ({
252252
*/
253253
export type CompositionWithOneOfAndSimpleArrayDictionary = {
254254
propA?: (boolean | {
255-
[key: string]: Array<(boolean)>;
255+
[key: string]: Array<boolean>;
256256
});
257257
};
258258

@@ -261,7 +261,7 @@ export type CompositionWithOneOfAndSimpleArrayDictionary = {
261261
*/
262262
export type CompositionWithOneOfAndSimpleDictionary = {
263263
propA?: (boolean | {
264-
[key: string]: (number);
264+
[key: string]: number;
265265
});
266266
};
267267

@@ -315,7 +315,7 @@ export type DictionaryWithArray = {
315315
*/
316316
export type DictionaryWithDictionary = {
317317
[key: string]: {
318-
[key: string]: (string);
318+
[key: string]: string;
319319
};
320320
};
321321

@@ -332,7 +332,7 @@ export type DictionaryWithProperties = {
332332
export type DictionaryWithPropertiesAndAdditionalProperties = {
333333
foo?: number;
334334
bar?: boolean;
335-
[key: string]: (string | number | boolean) | undefined;
335+
[key: string]: string | number | boolean | undefined;
336336
};
337337

338338
/**
@@ -346,7 +346,7 @@ export type DictionaryWithReference = {
346346
* This is a string dictionary
347347
*/
348348
export type DictionaryWithString = {
349-
[key: string]: (string);
349+
[key: string]: string;
350350
};
351351

352352
/**
@@ -581,17 +581,17 @@ export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [
581581
*/
582582
export type ModelWithArray = {
583583
prop?: Array<ModelWithString>;
584-
propWithFile?: Array<((Blob | File))>;
585-
propWithNumber?: Array<(number)>;
584+
propWithFile?: Array<Blob | File>;
585+
propWithNumber?: Array<number>;
586586
};
587587

588588
/**
589589
* This is a model with one property containing an array
590590
*/
591591
export type ModelWithArrayReadOnlyAndWriteOnly = {
592592
prop?: Array<ModelWithReadOnlyAndWriteOnly>;
593-
propWithFile?: Array<((Blob | File))>;
594-
propWithNumber?: Array<(number)>;
593+
propWithFile?: Array<Blob | File>;
594+
propWithNumber?: Array<number>;
595595
};
596596

597597
/**
@@ -664,7 +664,7 @@ export type ModelWithConstantSizeArray = [
664664
*/
665665
export type ModelWithDictionary = {
666666
prop?: {
667-
[key: string]: (string);
667+
[key: string]: string;
668668
};
669669
};
670670

@@ -759,7 +759,7 @@ export type ModelWithInteger = {
759759
};
760760

761761
export type ModelWithNestedArrayEnums = {
762-
array_strings?: Array<(string)>;
762+
array_strings?: Array<string>;
763763
data?: (ModelWithNestedArrayEnumsData);
764764
};
765765

@@ -791,13 +791,13 @@ export type ModelWithNestedCompositionEnums = {
791791
*/
792792
export type ModelWithNestedEnums = {
793793
dictionaryWithEnum?: {
794-
[key: string]: ('Success' | 'Warning' | 'Error');
794+
[key: string]: 'Success' | 'Warning' | 'Error';
795795
};
796796
dictionaryWithEnumFromDescription?: {
797-
[key: string]: (number);
797+
[key: string]: number;
798798
};
799-
arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>;
800-
arrayWithDescription?: Array<(number)>;
799+
arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>;
800+
arrayWithDescription?: Array<number>;
801801
/**
802802
* This is a simple enum with strings
803803
*/
@@ -1021,7 +1021,7 @@ export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_Sy
10211021
export type Pageable = {
10221022
page?: number;
10231023
size?: number;
1024-
sort?: Array<(string)>;
1024+
sort?: Array<string>;
10251025
};
10261026

10271027
/**
@@ -1079,7 +1079,7 @@ export type SimpleBoolean = boolean;
10791079
/**
10801080
* This is a simple file
10811081
*/
1082-
export type SimpleFile = (Blob | File);
1082+
export type SimpleFile = Blob | File;
10831083

10841084
/**
10851085
* This is a simple number
@@ -1105,23 +1105,23 @@ export type CollectionFormatData = {
11051105
/**
11061106
* This is an array parameter that is sent as csv format (comma-separated values)
11071107
*/
1108-
parameterArrayCsv: Array<(string)> | null;
1108+
parameterArrayCsv: Array<string> | null;
11091109
/**
11101110
* This is an array parameter that is sent as multi format (multiple parameter instances)
11111111
*/
1112-
parameterArrayMulti: Array<(string)> | null;
1112+
parameterArrayMulti: Array<string> | null;
11131113
/**
11141114
* This is an array parameter that is sent as pipes format (pipe-separated values)
11151115
*/
1116-
parameterArrayPipes: Array<(string)> | null;
1116+
parameterArrayPipes: Array<string> | null;
11171117
/**
11181118
* This is an array parameter that is sent as ssv format (space-separated values)
11191119
*/
1120-
parameterArraySsv: Array<(string)> | null;
1120+
parameterArraySsv: Array<string> | null;
11211121
/**
11221122
* This is an array parameter that is sent as tsv format (tab-separated values)
11231123
*/
1124-
parameterArrayTsv: Array<(string)> | null;
1124+
parameterArrayTsv: Array<string> | null;
11251125
};
11261126

11271127
export type ComplexTypesData = {
@@ -1151,7 +1151,7 @@ export type ComplexParamsData = {
11511151
enabled?: boolean;
11521152
readonly type: 'Monkey' | 'Horse' | 'Bird';
11531153
listOfModels?: Array<ModelWithString> | null;
1154-
listOfStrings?: Array<(string)> | null;
1154+
listOfStrings?: Array<string> | null;
11551155
parameters: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary);
11561156
readonly user?: {
11571157
readonly id?: number;
@@ -1313,7 +1313,7 @@ export type FileResponseData = {
13131313
id: string;
13141314
};
13151315

1316-
export type FileResponseResponse = ((Blob | File));
1316+
export type FileResponseResponse = (Blob | File);
13171317

13181318
export type PostApiFormDataData = {
13191319
/**
@@ -1330,13 +1330,13 @@ export type CallWithResultFromHeaderResponse = (string);
13301330

13311331
export type MultipartRequestData = {
13321332
formData?: {
1333-
content?: (Blob | File);
1333+
content?: Blob | File;
13341334
data?: ((ModelWithString) | null);
13351335
};
13361336
};
13371337

13381338
export type MultipartResponseResponse = ({
1339-
file?: (Blob | File);
1339+
file?: Blob | File;
13401340
metadata?: {
13411341
foo?: string;
13421342
bar?: string;
@@ -1498,7 +1498,7 @@ export type TypesData = {
14981498
/**
14991499
* This is an array parameter
15001500
*/
1501-
parameterArray: Array<(string)> | null;
1501+
parameterArray: Array<string> | null;
15021502
/**
15031503
* This is a boolean parameter
15041504
*/
@@ -1543,7 +1543,7 @@ export type TypesResponse = (number | string | boolean | {
15431543
});
15441544

15451545
export type UploadFileData = {
1546-
formData: (Blob | File);
1546+
formData: Blob | File;
15471547
};
15481548

15491549
export type UploadFileResponse = (boolean);

0 commit comments

Comments
 (0)