Skip to content

Commit 37412df

Browse files
committed
add oneof tests for ts fetch
1 parent bf7ad8c commit 37412df

7 files changed

Lines changed: 258 additions & 1 deletion

File tree

modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@ components:
9393
- "optionTwo"
9494
type: string
9595
required:
96-
- discriminatorField
96+
- discriminatorField
97+
OneOfPrimitiveTypes:
98+
type: object
99+
properties:
100+
value:
101+
oneOf:
102+
- type: boolean
103+
- type: integer
104+
format: int64
105+
- $ref: "#/components/schemas/TestA"
106+
- type: array
107+
items:
108+
$ref: "#/components/schemas/TestA"

samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
apis/DefaultApi.ts
22
apis/index.ts
33
docs/DefaultApi.md
4+
docs/OneOfPrimitiveTypes.md
5+
docs/OneOfPrimitiveTypesValue.md
46
docs/OptionOne.md
57
docs/OptionTwo.md
68
docs/TestA.md
@@ -9,6 +11,8 @@ docs/TestB.md
911
docs/TestDiscriminatorResponse.md
1012
docs/TestResponse.md
1113
index.ts
14+
models/OneOfPrimitiveTypes.ts
15+
models/OneOfPrimitiveTypesValue.ts
1216
models/OptionOne.ts
1317
models/OptionTwo.ts
1418
models/TestA.ts
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# OneOfPrimitiveTypes
3+
4+
5+
## Properties
6+
7+
Name | Type
8+
------------ | -------------
9+
`value` | [OneOfPrimitiveTypesValue](OneOfPrimitiveTypesValue.md)
10+
11+
## Example
12+
13+
```typescript
14+
import type { OneOfPrimitiveTypes } from ''
15+
16+
// TODO: Update the object below with actual values
17+
const example = {
18+
"value": null,
19+
} satisfies OneOfPrimitiveTypes
20+
21+
console.log(example)
22+
23+
// Convert the instance to a JSON string
24+
const exampleJSON: string = JSON.stringify(example)
25+
console.log(exampleJSON)
26+
27+
// Parse the JSON string back to an object
28+
const exampleParsed = JSON.parse(exampleJSON) as OneOfPrimitiveTypes
29+
console.log(exampleParsed)
30+
```
31+
32+
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
33+
34+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# OneOfPrimitiveTypesValue
3+
4+
5+
## Properties
6+
7+
Name | Type
8+
------------ | -------------
9+
`foo` | string
10+
11+
## Example
12+
13+
```typescript
14+
import type { OneOfPrimitiveTypesValue } from ''
15+
16+
// TODO: Update the object below with actual values
17+
const example = {
18+
"foo": null,
19+
} satisfies OneOfPrimitiveTypesValue
20+
21+
console.log(example)
22+
23+
// Convert the instance to a JSON string
24+
const exampleJSON: string = JSON.stringify(example)
25+
console.log(exampleJSON)
26+
27+
// Parse the JSON string back to an object
28+
const exampleParsed = JSON.parse(exampleJSON) as OneOfPrimitiveTypesValue
29+
console.log(exampleParsed)
30+
```
31+
32+
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
33+
34+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* testing oneOf without discriminator
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 1.0.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { mapValues } from '../runtime';
16+
import type { OneOfPrimitiveTypesValue } from './OneOfPrimitiveTypesValue';
17+
import {
18+
OneOfPrimitiveTypesValueFromJSON,
19+
OneOfPrimitiveTypesValueFromJSONTyped,
20+
OneOfPrimitiveTypesValueToJSON,
21+
OneOfPrimitiveTypesValueToJSONTyped,
22+
} from './OneOfPrimitiveTypesValue';
23+
24+
/**
25+
*
26+
* @export
27+
* @interface OneOfPrimitiveTypes
28+
*/
29+
export interface OneOfPrimitiveTypes {
30+
/**
31+
*
32+
* @type {OneOfPrimitiveTypesValue}
33+
* @memberof OneOfPrimitiveTypes
34+
*/
35+
value?: OneOfPrimitiveTypesValue;
36+
}
37+
38+
/**
39+
* Check if a given object implements the OneOfPrimitiveTypes interface.
40+
*/
41+
export function instanceOfOneOfPrimitiveTypes(value: object): value is OneOfPrimitiveTypes {
42+
return true;
43+
}
44+
45+
export function OneOfPrimitiveTypesFromJSON(json: any): OneOfPrimitiveTypes {
46+
return OneOfPrimitiveTypesFromJSONTyped(json, false);
47+
}
48+
49+
export function OneOfPrimitiveTypesFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypes {
50+
if (json == null) {
51+
return json;
52+
}
53+
return {
54+
55+
'value': json['value'] == null ? undefined : OneOfPrimitiveTypesValueFromJSON(json['value']),
56+
};
57+
}
58+
59+
export function OneOfPrimitiveTypesToJSON(json: any): OneOfPrimitiveTypes {
60+
return OneOfPrimitiveTypesToJSONTyped(json, false);
61+
}
62+
63+
export function OneOfPrimitiveTypesToJSONTyped(value?: OneOfPrimitiveTypes | null, ignoreDiscriminator: boolean = false): any {
64+
if (value == null) {
65+
return value;
66+
}
67+
68+
return {
69+
70+
'value': OneOfPrimitiveTypesValueToJSON(value['value']),
71+
};
72+
}
73+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* testing oneOf without discriminator
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 1.0.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import type { TestA } from './TestA';
16+
import {
17+
instanceOfTestA,
18+
TestAFromJSON,
19+
TestAFromJSONTyped,
20+
TestAToJSON,
21+
} from './TestA';
22+
import type { TestA } from './TestA';
23+
import {
24+
instanceOfTestA,
25+
TestAFromJSON,
26+
TestAFromJSONTyped,
27+
TestAToJSON,
28+
} from './TestA';
29+
30+
/**
31+
* @type OneOfPrimitiveTypesValue
32+
*
33+
* @export
34+
*/
35+
export type OneOfPrimitiveTypesValue = Array<TestA> | TestA | boolean | number;
36+
37+
export function OneOfPrimitiveTypesValueFromJSON(json: any): OneOfPrimitiveTypesValue {
38+
return OneOfPrimitiveTypesValueFromJSONTyped(json, false);
39+
}
40+
41+
export function OneOfPrimitiveTypesValueFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypesValue {
42+
if (json == null) {
43+
return json;
44+
}
45+
if (typeof json !== 'object') {
46+
return json;
47+
}
48+
if (instanceOfTestA(json)) {
49+
return TestAFromJSONTyped(json, true);
50+
}
51+
if (Array.isArray(json)) {
52+
if (json.every(item => typeof item === 'object')) {
53+
if (json.every(item => instanceOfTestA(item))) {
54+
return json.map(value => TestAFromJSONTyped(value, true));
55+
}
56+
}
57+
return json;
58+
}
59+
if (typeof json === 'boolean') {
60+
return json;
61+
}
62+
if (typeof json === 'number') {
63+
return json;
64+
}
65+
return {} as any;
66+
}
67+
68+
export function OneOfPrimitiveTypesValueToJSON(json: any): any {
69+
return OneOfPrimitiveTypesValueToJSONTyped(json, false);
70+
}
71+
72+
export function OneOfPrimitiveTypesValueToJSONTyped(value?: OneOfPrimitiveTypesValue | null, ignoreDiscriminator: boolean = false): any {
73+
if (value == null) {
74+
return value;
75+
}
76+
if (typeof value !== 'object') {
77+
return value;
78+
}
79+
if (instanceOfTestA(value)) {
80+
return TestAToJSON(value as TestA);
81+
}
82+
if (Array.isArray(value)) {
83+
if (value.every(item => typeof item === 'object')) {
84+
if (value.every(item => instanceOfTestA(item))) {
85+
return value.map(value => TestAToJSON(value as TestA));
86+
}
87+
}
88+
return value;
89+
}
90+
if (typeof value === 'boolean') {
91+
return value;
92+
}
93+
if (typeof value === 'number') {
94+
return value;
95+
}
96+
return {};
97+
}
98+

samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* tslint:disable */
22
/* eslint-disable */
3+
export * from './OneOfPrimitiveTypes';
4+
export * from './OneOfPrimitiveTypesValue';
35
export * from './OptionOne';
46
export * from './OptionTwo';
57
export * from './TestA';

0 commit comments

Comments
 (0)