Skip to content

Commit

Permalink
add one-of string & array support
Browse files Browse the repository at this point in the history
  • Loading branch information
thesn10 committed Nov 26, 2024
1 parent 55a38de commit c95f4e2
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,38 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
/test-array:
get:
operationId: testArray
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestArrayResponse'
components:
schemas:
TestArrayResponse:
oneOf:
- type: array
items:
$ref: "#/components/schemas/TestA"
- type: array
items:
$ref: "#/components/schemas/TestB"
- type: array
items:
type: string
TestResponse:
oneOf:
- $ref: "#/components/schemas/TestA"
- $ref: "#/components/schemas/TestB"
- type: string
enum:
- StringEnum1
- StringEnum2
- type: string
TestA:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apis/DefaultApi.ts
apis/index.ts
index.ts
models/TestA.ts
models/TestArrayResponse.ts
models/TestB.ts
models/TestResponse.ts
models/index.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

import * as runtime from '../runtime';
import type {
TestArrayResponse,
TestResponse,
} from '../models/index';
import {
TestArrayResponseFromJSON,
TestArrayResponseToJSON,
TestResponseFromJSON,
TestResponseToJSON,
} from '../models/index';
Expand Down Expand Up @@ -51,4 +54,28 @@ export class DefaultApi extends runtime.BaseAPI {
return await response.value();
}

/**
*/
async testArrayRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TestArrayResponse>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

const response = await this.request({
path: `/test-array`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => TestArrayResponseFromJSON(jsonValue));
}

/**
*/
async testArray(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TestArrayResponse> {
const response = await this.testArrayRaw(initOverrides);
return await response.value();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* tslint:disable */
/* eslint-disable */
/**
* testing oneOf without discriminator
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import type { TestA } from './TestA';
import {
instanceOfTestA,
TestAFromJSON,
TestAFromJSONTyped,
TestAToJSON,
} from './TestA';
import type { TestB } from './TestB';
import {
instanceOfTestB,
TestBFromJSON,
TestBFromJSONTyped,
TestBToJSON,
} from './TestB';

/**
* @type TestArrayResponse
*
* @export
*/
export type TestArrayResponse = Array<TestA> | Array<TestB> | Array<string>;

export function TestArrayResponseFromJSON(json: any): TestArrayResponse {
return TestArrayResponseFromJSONTyped(json, false);
}

export function TestArrayResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestArrayResponse {
if (json == null) {
return json;
}
if (!(json instanceof Object)){
return {} as any;
}
if (Array.isArray(json) && json.every(item => item instanceof String)) {
return json as Array<string>;
}
if (Array.isArray(json) && json.every(item => item instanceof Object)) {
if (json.every(item => instanceOfTestB(item as Object))) {
return json.map(value => TestBFromJSONTyped(value, true));
}
if (json.every(item => instanceOfTestA(item as Object))) {
return json.map(value => TestAFromJSONTyped(value, true));
}
}

return {} as any;
}

export function TestArrayResponseToJSON(json: any): any {
return TestArrayResponseToJSONTyped(json, false);
}

export function TestArrayResponseToJSONTyped(value?: TestArrayResponse | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}


if (!(value instanceof Object)){
return {};
}
if (Array.isArray(value) && value.every(item => item instanceof String)) {
return value;
}
if (Array.isArray(value) && value.every(item => item instanceof Object)) {
if (value.every(item => instanceOfTestB(item as Object))) {
return value.map(value => TestBToJSON(value as TestB));
}
if (value.every(item => instanceOfTestA(item as Object))) {
return value.map(value => TestAToJSON(value as TestA));
}
}

return {};
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
*
* @export
*/
export type TestResponse = TestA | TestB;
export type TestResponse = "StringEnum1" | "StringEnum2" | TestA | TestB | string;

export function TestResponseFromJSON(json: any): TestResponse {
return TestResponseFromJSONTyped(json, false);
Expand All @@ -42,12 +42,24 @@ export function TestResponseFromJSONTyped(json: any, ignoreDiscriminator: boolea
if (json == null) {
return json;
}
if (instanceOfTestA(json)) {
return TestAFromJSONTyped(json, true);
if (json === "StringEnum1") {
return json;
}
if (json === "StringEnum2") {
return json;
}
if (json instanceof String) {
return json as TestResponse;
}
if (!(json instanceof Object)){
return {} as any;
}
if (instanceOfTestB(json)) {
return TestBFromJSONTyped(json, true);
}
if (instanceOfTestA(json)) {
return TestAFromJSONTyped(json, true);
}

return {} as any;
}
Expand All @@ -61,12 +73,25 @@ export function TestResponseToJSONTyped(value?: TestResponse | null, ignoreDiscr
return value;
}

if (instanceOfTestA(value)) {
return TestAToJSON(value as TestA);

if (value === "StringEnum1") {
return value;
}
if (value === "StringEnum2") {
return value;
}
if (value instanceof String) {
return value;
}
if (!(value instanceof Object)){
return {};
}
if (instanceOfTestB(value)) {
return TestBToJSON(value as TestB);
}
if (instanceOfTestA(value)) {
return TestAToJSON(value as TestA);
}

return {};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* tslint:disable */
/* eslint-disable */
export * from './TestA';
export * from './TestArrayResponse';
export * from './TestB';
export * from './TestResponse';

0 comments on commit c95f4e2

Please sign in to comment.