From 785ecb4cbe629cbf8077ae49f4205e3c6e90bc66 Mon Sep 17 00:00:00 2001 From: Pierre Segalen Date: Thu, 22 Jan 2026 22:22:38 +0100 Subject: [PATCH 1/4] Fixed TypeScript code generation for oneOf using arrays --- .../resources/typescript-fetch/modelOneOf.mustache | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache index d9a828e42cdb..46352ea71acd 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache @@ -70,15 +70,15 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{#items}} {{#isDateType}} if (Array.isArray(json)) { - if (json.every(item => !(isNaN(new Date(json).getTime()))) { - return json.map(value => new Date(json); + if (json.every(item => !(isNaN(new Date(item).getTime())))) { + return json.map(value => new Date(value)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(json)) { - if (json.every(item => !(isNaN(new Date(json).getTime()))) { - return json.map(value => new Date(json); + if (json.every(item => !(isNaN(new Date(item).getTime())))) { + return json.map(value => new Date(value)); } } {{/isDateTimeType}} @@ -188,14 +188,14 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis {{#isDateType}} if (Array.isArray(value)) { if (value.every(item => item instanceof Date) { - return value.map(value => value.toISOString().substring(0,10))); + return value.map(value => value.toISOString().substring(0,10)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(value)) { - if (value.every(item => item instanceof Date) { - return value.map(value => value.toISOString(); + if (value.every(item => item instanceof Date)) { + return value.map(item => item.toISOString()); } } {{/isDateTimeType}} From bf7ad8ce4f484fee8fa6cf55c4b469bc480c94a2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 2 Feb 2026 12:21:51 +0800 Subject: [PATCH 2/4] add oneOf tests in composed test spec for TS --- .../test/resources/3_0/composed-schemas.yaml | 15 +++++++- .../composed-schemas/.openapi-generator/FILES | 2 + .../builds/composed-schemas/api.ts | 8 ++++ .../docs/OneOfPrimitiveTypes.md | 20 ++++++++++ .../docs/OneOfPrimitiveTypesValue.md | 22 +++++++++++ .../composed-schemas/.openapi-generator/FILES | 2 + .../models/ObjectSerializer.ts | 6 +++ .../models/OneOfPrimitiveTypes.ts | 37 +++++++++++++++++++ .../models/OneOfPrimitiveTypesValue.ts | 34 +++++++++++++++++ .../builds/composed-schemas/models/all.ts | 2 + .../composed-schemas/types/ObjectParamAPI.ts | 2 + .../composed-schemas/types/ObservableAPI.ts | 2 + .../composed-schemas/types/PromiseAPI.ts | 2 + 13 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypes.md create mode 100644 samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypesValue.md create mode 100644 samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypes.ts create mode 100644 samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypesValue.ts diff --git a/modules/openapi-generator/src/test/resources/3_0/composed-schemas.yaml b/modules/openapi-generator/src/test/resources/3_0/composed-schemas.yaml index 08e73f1d2ee6..b437b151a609 100644 --- a/modules/openapi-generator/src/test/resources/3_0/composed-schemas.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/composed-schemas.yaml @@ -104,4 +104,17 @@ components: hunts: type: boolean required: - - pet_type \ No newline at end of file + - pet_type + + OneOfPrimitiveTypes: + type: object + properties: + value: + oneOf: + - type: boolean + - type: integer + format: int64 + - $ref: "#/components/schemas/PetByAge" + - type: array + items: + $ref: "#/components/schemas/PetByAge" diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/.openapi-generator/FILES b/samples/client/petstore/typescript-axios/builds/composed-schemas/.openapi-generator/FILES index 2c3376618ea6..5c24a7891ffd 100644 --- a/samples/client/petstore/typescript-axios/builds/composed-schemas/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/.openapi-generator/FILES @@ -8,6 +8,8 @@ docs/Cat.md docs/DefaultApi.md docs/Dog.md docs/FilePostRequest.md +docs/OneOfPrimitiveTypes.md +docs/OneOfPrimitiveTypesValue.md docs/PetByAge.md docs/PetByType.md docs/PetsFilteredPatchRequest.md diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts b/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts index 53c2afbbc9be..f4ec14130318 100644 --- a/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/api.ts @@ -47,6 +47,14 @@ export type DogBreedEnum = typeof DogBreedEnum[keyof typeof DogBreedEnum]; export interface FilePostRequest { 'file'?: any; } +export interface OneOfPrimitiveTypes { + 'value'?: OneOfPrimitiveTypesValue; +} +/** + * @type OneOfPrimitiveTypesValue + */ +export type OneOfPrimitiveTypesValue = Array | PetByAge | boolean | number; + export interface PetByAge { 'age': number; 'nickname'?: string; diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypes.md b/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypes.md new file mode 100644 index 000000000000..31cf1c6cb41f --- /dev/null +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypes.md @@ -0,0 +1,20 @@ +# OneOfPrimitiveTypes + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | [**OneOfPrimitiveTypesValue**](OneOfPrimitiveTypesValue.md) | | [optional] [default to undefined] + +## Example + +```typescript +import { OneOfPrimitiveTypes } from './api'; + +const instance: OneOfPrimitiveTypes = { + value, +}; +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypesValue.md b/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypesValue.md new file mode 100644 index 000000000000..7f7fb2abc6d5 --- /dev/null +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/docs/OneOfPrimitiveTypesValue.md @@ -0,0 +1,22 @@ +# OneOfPrimitiveTypesValue + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**age** | **number** | | [default to undefined] +**nickname** | **string** | | [optional] [default to undefined] + +## Example + +```typescript +import { OneOfPrimitiveTypesValue } from './api'; + +const instance: OneOfPrimitiveTypesValue = { + age, + nickname, +}; +``` + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/.openapi-generator/FILES b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/.openapi-generator/FILES index 2afec448db09..1fbc4ed002aa 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/.openapi-generator/FILES @@ -16,6 +16,8 @@ models/Cat.ts models/Dog.ts models/FilePostRequest.ts models/ObjectSerializer.ts +models/OneOfPrimitiveTypes.ts +models/OneOfPrimitiveTypesValue.ts models/PetByAge.ts models/PetByType.ts models/PetsFilteredPatchRequest.ts diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts index 46d1a1994ba7..7ae441bb4a06 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/ObjectSerializer.ts @@ -1,6 +1,8 @@ export * from '../models/Cat'; export * from '../models/Dog'; export * from '../models/FilePostRequest'; +export * from '../models/OneOfPrimitiveTypes'; +export * from '../models/OneOfPrimitiveTypesValue'; export * from '../models/PetByAge'; export * from '../models/PetByType'; export * from '../models/PetsFilteredPatchRequest'; @@ -9,6 +11,8 @@ export * from '../models/PetsPatchRequest'; import { Cat } from '../models/Cat'; import { Dog , DogBreedEnum } from '../models/Dog'; import { FilePostRequest } from '../models/FilePostRequest'; +import { OneOfPrimitiveTypes } from '../models/OneOfPrimitiveTypes'; +import { OneOfPrimitiveTypesValueClass } from '../models/OneOfPrimitiveTypesValue'; import { PetByAge } from '../models/PetByAge'; import { PetByType, PetByTypePetTypeEnum } from '../models/PetByType'; import { PetsFilteredPatchRequest , PetsFilteredPatchRequestPetTypeEnum } from '../models/PetsFilteredPatchRequest'; @@ -37,6 +41,8 @@ let typeMap: {[index: string]: any} = { "Cat": Cat, "Dog": Dog, "FilePostRequest": FilePostRequest, + "OneOfPrimitiveTypes": OneOfPrimitiveTypes, + "OneOfPrimitiveTypesValue": OneOfPrimitiveTypesValueClass, "PetByAge": PetByAge, "PetByType": PetByType, "PetsFilteredPatchRequest": PetsFilteredPatchRequest, diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypes.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypes.ts new file mode 100644 index 000000000000..b40266d8cad0 --- /dev/null +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypes.ts @@ -0,0 +1,37 @@ +/** + * Example + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * OpenAPI spec version: 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 { OneOfPrimitiveTypesValue } from '../models/OneOfPrimitiveTypesValue'; +import { HttpFile } from '../http/http'; + +export class OneOfPrimitiveTypes { + 'value'?: OneOfPrimitiveTypesValue; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "value", + "baseName": "value", + "type": "OneOfPrimitiveTypesValue", + "format": "" + } ]; + + static getAttributeTypeMap() { + return OneOfPrimitiveTypes.attributeTypeMap; + } + + public constructor() { + } +} diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypesValue.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypesValue.ts new file mode 100644 index 000000000000..cb8c4426d944 --- /dev/null +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/OneOfPrimitiveTypesValue.ts @@ -0,0 +1,34 @@ +/** + * Example + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * OpenAPI spec version: 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 { PetByAge } from '../models/PetByAge'; +import { HttpFile } from '../http/http'; + +/** + * @type OneOfPrimitiveTypesValue + * Type + * @export + */ +export type OneOfPrimitiveTypesValue = Array | PetByAge | boolean | number; + +/** +* @type OneOfPrimitiveTypesValueClass +* @export +*/ +export class OneOfPrimitiveTypesValueClass { + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; +} + + + diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/all.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/all.ts index 195ee97a007b..c8cde6b7d55f 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/all.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/all.ts @@ -1,6 +1,8 @@ export * from '../models/Cat' export * from '../models/Dog' export * from '../models/FilePostRequest' +export * from '../models/OneOfPrimitiveTypes' +export * from '../models/OneOfPrimitiveTypesValue' export * from '../models/PetByAge' export * from '../models/PetByType' export * from '../models/PetsFilteredPatchRequest' diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObjectParamAPI.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObjectParamAPI.ts index 258ca68d9b67..77757eda1230 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObjectParamAPI.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObjectParamAPI.ts @@ -5,6 +5,8 @@ import type { Middleware } from '../middleware'; import { Cat } from '../models/Cat'; import { Dog } from '../models/Dog'; import { FilePostRequest } from '../models/FilePostRequest'; +import { OneOfPrimitiveTypes } from '../models/OneOfPrimitiveTypes'; +import { OneOfPrimitiveTypesValue } from '../models/OneOfPrimitiveTypesValue'; import { PetByAge } from '../models/PetByAge'; import { PetByType } from '../models/PetByType'; import { PetsFilteredPatchRequest } from '../models/PetsFilteredPatchRequest'; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObservableAPI.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObservableAPI.ts index 3f657b1f3144..caa56d1ea92c 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObservableAPI.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/ObservableAPI.ts @@ -6,6 +6,8 @@ import {mergeMap, map} from '../rxjsStub'; import { Cat } from '../models/Cat'; import { Dog } from '../models/Dog'; import { FilePostRequest } from '../models/FilePostRequest'; +import { OneOfPrimitiveTypes } from '../models/OneOfPrimitiveTypes'; +import { OneOfPrimitiveTypesValue } from '../models/OneOfPrimitiveTypesValue'; import { PetByAge } from '../models/PetByAge'; import { PetByType } from '../models/PetByType'; import { PetsFilteredPatchRequest } from '../models/PetsFilteredPatchRequest'; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/PromiseAPI.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/PromiseAPI.ts index cc29d2008689..c909f6db8493 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/PromiseAPI.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/types/PromiseAPI.ts @@ -5,6 +5,8 @@ import { PromiseMiddleware, Middleware, PromiseMiddlewareWrapper } from '../midd import { Cat } from '../models/Cat'; import { Dog } from '../models/Dog'; import { FilePostRequest } from '../models/FilePostRequest'; +import { OneOfPrimitiveTypes } from '../models/OneOfPrimitiveTypes'; +import { OneOfPrimitiveTypesValue } from '../models/OneOfPrimitiveTypesValue'; import { PetByAge } from '../models/PetByAge'; import { PetByType } from '../models/PetByType'; import { PetsFilteredPatchRequest } from '../models/PetsFilteredPatchRequest'; From 37412df306303fd33e65dbc1bf25a73ba0af9990 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 2 Feb 2026 12:32:51 +0800 Subject: [PATCH 3/4] add oneof tests for ts fetch --- .../resources/3_0/typescript-fetch/oneOf.yaml | 14 ++- .../builds/oneOf/.openapi-generator/FILES | 4 + .../builds/oneOf/docs/OneOfPrimitiveTypes.md | 34 +++++++ .../oneOf/docs/OneOfPrimitiveTypesValue.md | 34 +++++++ .../oneOf/models/OneOfPrimitiveTypes.ts | 73 ++++++++++++++ .../oneOf/models/OneOfPrimitiveTypesValue.ts | 98 +++++++++++++++++++ .../builds/oneOf/models/index.ts | 2 + 7 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypes.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypesValue.ts diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml index 958b601804dc..10a02efaa1a9 100644 --- a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml @@ -93,4 +93,16 @@ components: - "optionTwo" type: string required: - - discriminatorField \ No newline at end of file + - discriminatorField + OneOfPrimitiveTypes: + type: object + properties: + value: + oneOf: + - type: boolean + - type: integer + format: int64 + - $ref: "#/components/schemas/TestA" + - type: array + items: + $ref: "#/components/schemas/TestA" diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES index 20834d7a9398..622cab8cf02b 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES @@ -1,6 +1,8 @@ apis/DefaultApi.ts apis/index.ts docs/DefaultApi.md +docs/OneOfPrimitiveTypes.md +docs/OneOfPrimitiveTypesValue.md docs/OptionOne.md docs/OptionTwo.md docs/TestA.md @@ -9,6 +11,8 @@ docs/TestB.md docs/TestDiscriminatorResponse.md docs/TestResponse.md index.ts +models/OneOfPrimitiveTypes.ts +models/OneOfPrimitiveTypesValue.ts models/OptionOne.ts models/OptionTwo.ts models/TestA.ts diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md new file mode 100644 index 000000000000..94edc93de9ab --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md @@ -0,0 +1,34 @@ + +# OneOfPrimitiveTypes + + +## Properties + +Name | Type +------------ | ------------- +`value` | [OneOfPrimitiveTypesValue](OneOfPrimitiveTypesValue.md) + +## Example + +```typescript +import type { OneOfPrimitiveTypes } from '' + +// TODO: Update the object below with actual values +const example = { + "value": null, +} satisfies OneOfPrimitiveTypes + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as OneOfPrimitiveTypes +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md new file mode 100644 index 000000000000..a8790293e291 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md @@ -0,0 +1,34 @@ + +# OneOfPrimitiveTypesValue + + +## Properties + +Name | Type +------------ | ------------- +`foo` | string + +## Example + +```typescript +import type { OneOfPrimitiveTypesValue } from '' + +// TODO: Update the object below with actual values +const example = { + "foo": null, +} satisfies OneOfPrimitiveTypesValue + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as OneOfPrimitiveTypesValue +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypes.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypes.ts new file mode 100644 index 000000000000..957e73451efc --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypes.ts @@ -0,0 +1,73 @@ +/* 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 { mapValues } from '../runtime'; +import type { OneOfPrimitiveTypesValue } from './OneOfPrimitiveTypesValue'; +import { + OneOfPrimitiveTypesValueFromJSON, + OneOfPrimitiveTypesValueFromJSONTyped, + OneOfPrimitiveTypesValueToJSON, + OneOfPrimitiveTypesValueToJSONTyped, +} from './OneOfPrimitiveTypesValue'; + +/** + * + * @export + * @interface OneOfPrimitiveTypes + */ +export interface OneOfPrimitiveTypes { + /** + * + * @type {OneOfPrimitiveTypesValue} + * @memberof OneOfPrimitiveTypes + */ + value?: OneOfPrimitiveTypesValue; +} + +/** + * Check if a given object implements the OneOfPrimitiveTypes interface. + */ +export function instanceOfOneOfPrimitiveTypes(value: object): value is OneOfPrimitiveTypes { + return true; +} + +export function OneOfPrimitiveTypesFromJSON(json: any): OneOfPrimitiveTypes { + return OneOfPrimitiveTypesFromJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypes { + if (json == null) { + return json; + } + return { + + 'value': json['value'] == null ? undefined : OneOfPrimitiveTypesValueFromJSON(json['value']), + }; +} + +export function OneOfPrimitiveTypesToJSON(json: any): OneOfPrimitiveTypes { + return OneOfPrimitiveTypesToJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesToJSONTyped(value?: OneOfPrimitiveTypes | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'value': OneOfPrimitiveTypesValueToJSON(value['value']), + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypesValue.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypesValue.ts new file mode 100644 index 000000000000..fd7e076d6f76 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OneOfPrimitiveTypesValue.ts @@ -0,0 +1,98 @@ +/* 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 { TestA } from './TestA'; +import { + instanceOfTestA, + TestAFromJSON, + TestAFromJSONTyped, + TestAToJSON, +} from './TestA'; + +/** + * @type OneOfPrimitiveTypesValue + * + * @export + */ +export type OneOfPrimitiveTypesValue = Array | TestA | boolean | number; + +export function OneOfPrimitiveTypesValueFromJSON(json: any): OneOfPrimitiveTypesValue { + return OneOfPrimitiveTypesValueFromJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesValueFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypesValue { + if (json == null) { + return json; + } + if (typeof json !== 'object') { + return json; + } + if (instanceOfTestA(json)) { + return TestAFromJSONTyped(json, true); + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'object')) { + if (json.every(item => instanceOfTestA(item))) { + return json.map(value => TestAFromJSONTyped(value, true)); + } + } + return json; + } + if (typeof json === 'boolean') { + return json; + } + if (typeof json === 'number') { + return json; + } + return {} as any; +} + +export function OneOfPrimitiveTypesValueToJSON(json: any): any { + return OneOfPrimitiveTypesValueToJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesValueToJSONTyped(value?: OneOfPrimitiveTypesValue | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (typeof value !== 'object') { + return value; + } + if (instanceOfTestA(value)) { + return TestAToJSON(value as TestA); + } + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'object')) { + if (value.every(item => instanceOfTestA(item))) { + return value.map(value => TestAToJSON(value as TestA)); + } + } + return value; + } + if (typeof value === 'boolean') { + return value; + } + if (typeof value === 'number') { + return value; + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts index 79f8303e9ed5..9ef854f6741c 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts @@ -1,5 +1,7 @@ /* tslint:disable */ /* eslint-disable */ +export * from './OneOfPrimitiveTypes'; +export * from './OneOfPrimitiveTypesValue'; export * from './OptionOne'; export * from './OptionTwo'; export * from './TestA'; From c6e5d51574f5b42295caf927cf0c856ef492be6c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 2 Feb 2026 12:44:38 +0800 Subject: [PATCH 4/4] update config --- bin/configs/typescript-fetch-oneOf.yaml | 6 + .../typescript-fetch/builds/oneOf/.gitignore | 4 + .../typescript-fetch/builds/oneOf/.npmignore | 1 + .../builds/oneOf/.openapi-generator/FILES | 33 +- .../typescript-fetch/builds/oneOf/README.md | 117 +++++ .../builds/oneOf/docs/DefaultApi.md | 18 +- .../builds/oneOf/docs/OneOfPrimitiveTypes.md | 2 +- .../oneOf/docs/OneOfPrimitiveTypesValue.md | 2 +- .../builds/oneOf/docs/OptionOne.md | 2 +- .../builds/oneOf/docs/OptionTwo.md | 2 +- .../builds/oneOf/docs/TestA.md | 2 +- .../builds/oneOf/docs/TestArrayResponse.md | 2 +- .../builds/oneOf/docs/TestB.md | 2 +- .../oneOf/docs/TestDiscriminatorResponse.md | 2 +- .../builds/oneOf/docs/TestResponse.md | 2 +- .../builds/oneOf/package.json | 22 + .../builds/oneOf/src/apis/DefaultApi.ts | 141 ++++++ .../builds/oneOf/src/apis/index.ts | 3 + .../builds/oneOf/src/index.ts | 5 + .../oneOf/src/models/OneOfPrimitiveTypes.ts | 73 +++ .../src/models/OneOfPrimitiveTypesValue.ts | 98 ++++ .../builds/oneOf/src/models/OptionOne.ts | 76 +++ .../builds/oneOf/src/models/OptionTwo.ts | 76 +++ .../builds/oneOf/src/models/TestA.ts | 66 +++ .../oneOf/src/models/TestArrayResponse.ts | 90 ++++ .../builds/oneOf/src/models/TestB.ts | 66 +++ .../src/models/TestDiscriminatorResponse.ts | 72 +++ .../builds/oneOf/src/models/TestResponse.ts | 82 ++++ .../builds/oneOf/src/models/index.ts | 11 + .../builds/oneOf/src/runtime.ts | 432 ++++++++++++++++++ .../builds/oneOf/tsconfig.json | 20 + 31 files changed, 1498 insertions(+), 32 deletions(-) create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/.gitignore create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/.npmignore create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/README.md create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/package.json create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/DefaultApi.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypes.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypesValue.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionOne.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionTwo.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestA.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestArrayResponse.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestB.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestDiscriminatorResponse.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestResponse.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/models/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/src/runtime.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/tsconfig.json diff --git a/bin/configs/typescript-fetch-oneOf.yaml b/bin/configs/typescript-fetch-oneOf.yaml index a6e57df4cd71..b19a44c2c37b 100644 --- a/bin/configs/typescript-fetch-oneOf.yaml +++ b/bin/configs/typescript-fetch-oneOf.yaml @@ -2,3 +2,9 @@ generatorName: typescript-fetch outputDir: samples/client/petstore/typescript-fetch/builds/oneOf inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml templateDir: modules/openapi-generator/src/main/resources/typescript-fetch +additionalProperties: + npmVersion: 1.0.0 + npmName: '@openapitools/typescript-fetch-petstore' + npmRepository: https://skimdb.npmjs.com/registry + snapshot: false + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/.gitignore b/samples/client/petstore/typescript-fetch/builds/oneOf/.gitignore new file mode 100644 index 000000000000..149b57654723 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/.npmignore b/samples/client/petstore/typescript-fetch/builds/oneOf/.npmignore new file mode 100644 index 000000000000..42061c01a1c7 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/.npmignore @@ -0,0 +1 @@ +README.md \ No newline at end of file diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES index 622cab8cf02b..a8e871e7404f 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES @@ -1,5 +1,6 @@ -apis/DefaultApi.ts -apis/index.ts +.gitignore +.npmignore +README.md docs/DefaultApi.md docs/OneOfPrimitiveTypes.md docs/OneOfPrimitiveTypesValue.md @@ -10,15 +11,19 @@ docs/TestArrayResponse.md docs/TestB.md docs/TestDiscriminatorResponse.md docs/TestResponse.md -index.ts -models/OneOfPrimitiveTypes.ts -models/OneOfPrimitiveTypesValue.ts -models/OptionOne.ts -models/OptionTwo.ts -models/TestA.ts -models/TestArrayResponse.ts -models/TestB.ts -models/TestDiscriminatorResponse.ts -models/TestResponse.ts -models/index.ts -runtime.ts +package.json +src/apis/DefaultApi.ts +src/apis/index.ts +src/index.ts +src/models/OneOfPrimitiveTypes.ts +src/models/OneOfPrimitiveTypesValue.ts +src/models/OptionOne.ts +src/models/OptionTwo.ts +src/models/TestA.ts +src/models/TestArrayResponse.ts +src/models/TestB.ts +src/models/TestDiscriminatorResponse.ts +src/models/TestResponse.ts +src/models/index.ts +src/runtime.ts +tsconfig.json diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/README.md b/samples/client/petstore/typescript-fetch/builds/oneOf/README.md new file mode 100644 index 000000000000..25fba32671ed --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/README.md @@ -0,0 +1,117 @@ +# @openapitools/typescript-fetch-petstore@1.0.0 + +A TypeScript SDK client for the localhost API. + +## Usage + +First, install the SDK from npm. + +```bash +npm install @openapitools/typescript-fetch-petstore --save +``` + +Next, try it out. + + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-petstore'; +import type { TestRequest } from '@openapitools/typescript-fetch-petstore'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-petstore SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.test(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + + +## Documentation + +### API Endpoints + +All URIs are relative to *http://localhost:3000* + +| Class | Method | HTTP request | Description +| ----- | ------ | ------------ | ------------- +*DefaultApi* | [**test**](docs/DefaultApi.md#test) | **GET** /test | +*DefaultApi* | [**testArray**](docs/DefaultApi.md#testarray) | **GET** /test-array | +*DefaultApi* | [**testDiscriminator**](docs/DefaultApi.md#testdiscriminator) | **GET** /test-discriminator | + + +### Models + +- [OneOfPrimitiveTypes](docs/OneOfPrimitiveTypes.md) +- [OneOfPrimitiveTypesValue](docs/OneOfPrimitiveTypesValue.md) +- [OptionOne](docs/OptionOne.md) +- [OptionTwo](docs/OptionTwo.md) +- [TestA](docs/TestA.md) +- [TestArrayResponse](docs/TestArrayResponse.md) +- [TestB](docs/TestB.md) +- [TestDiscriminatorResponse](docs/TestDiscriminatorResponse.md) +- [TestResponse](docs/TestResponse.md) + +### Authorization + +Endpoints do not require authorization. + + +## About + +This TypeScript SDK client supports the [Fetch API](https://fetch.spec.whatwg.org/) +and is automatically generated by the +[OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: `1.0.0` +- Package version: `1.0.0` +- Generator version: `7.20.0-SNAPSHOT` +- Build package: `org.openapitools.codegen.languages.TypeScriptFetchClientCodegen` + +The generated npm module supports the following: + +- Environments + * Node.js + * Webpack + * Browserify +- Language levels + * ES5 - you must have a Promises/A+ library installed + * ES6 +- Module systems + * CommonJS + * ES6 module system + + +## Development + +### Building + +To build the TypeScript source code, you need to have Node.js and npm installed. +After cloning the repository, navigate to the project directory and run: + +```bash +npm install +npm run build +``` + +### Publishing + +Once you've built the package, you can publish it to npm: + +```bash +npm publish +``` + +## License + +[]() diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/DefaultApi.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/DefaultApi.md index 270369707540..842468444b50 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/DefaultApi.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/DefaultApi.md @@ -22,11 +22,11 @@ All URIs are relative to *http://localhost:3000* import { Configuration, DefaultApi, -} from ''; -import type { TestRequest } from ''; +} from '@openapitools/typescript-fetch-petstore'; +import type { TestRequest } from '@openapitools/typescript-fetch-petstore'; async function example() { - console.log("🚀 Testing SDK..."); + console.log("🚀 Testing @openapitools/typescript-fetch-petstore SDK..."); const api = new DefaultApi(); try { @@ -79,11 +79,11 @@ No authorization required import { Configuration, DefaultApi, -} from ''; -import type { TestArrayRequest } from ''; +} from '@openapitools/typescript-fetch-petstore'; +import type { TestArrayRequest } from '@openapitools/typescript-fetch-petstore'; async function example() { - console.log("🚀 Testing SDK..."); + console.log("🚀 Testing @openapitools/typescript-fetch-petstore SDK..."); const api = new DefaultApi(); try { @@ -136,11 +136,11 @@ No authorization required import { Configuration, DefaultApi, -} from ''; -import type { TestDiscriminatorRequest } from ''; +} from '@openapitools/typescript-fetch-petstore'; +import type { TestDiscriminatorRequest } from '@openapitools/typescript-fetch-petstore'; async function example() { - console.log("🚀 Testing SDK..."); + console.log("🚀 Testing @openapitools/typescript-fetch-petstore SDK..."); const api = new DefaultApi(); try { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md index 94edc93de9ab..d5a0474328a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypes.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { OneOfPrimitiveTypes } from '' +import type { OneOfPrimitiveTypes } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md index a8790293e291..eabc8e68f443 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OneOfPrimitiveTypesValue.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { OneOfPrimitiveTypesValue } from '' +import type { OneOfPrimitiveTypesValue } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionOne.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionOne.md index cfb9d67b6cee..047ea34c303f 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionOne.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionOne.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { OptionOne } from '' +import type { OptionOne } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionTwo.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionTwo.md index bfb80f587b8b..f641d678c956 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionTwo.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/OptionTwo.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { OptionTwo } from '' +import type { OptionTwo } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestA.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestA.md index c1b89ab63a90..dbbd7447455f 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestA.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestA.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { TestA } from '' +import type { TestA } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestArrayResponse.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestArrayResponse.md index 7594da4c4baf..634cb22c8cbe 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestArrayResponse.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestArrayResponse.md @@ -10,7 +10,7 @@ Name | Type ## Example ```typescript -import type { TestArrayResponse } from '' +import type { TestArrayResponse } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestB.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestB.md index a930f36731b8..cfe74d849d12 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestB.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestB.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { TestB } from '' +import type { TestB } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestDiscriminatorResponse.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestDiscriminatorResponse.md index 12acff490180..978f386cb765 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestDiscriminatorResponse.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestDiscriminatorResponse.md @@ -11,7 +11,7 @@ Name | Type ## Example ```typescript -import type { TestDiscriminatorResponse } from '' +import type { TestDiscriminatorResponse } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestResponse.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestResponse.md index ab5595e1543a..55ecd8b3521f 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestResponse.md +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/TestResponse.md @@ -12,7 +12,7 @@ Name | Type ## Example ```typescript -import type { TestResponse } from '' +import type { TestResponse } from '@openapitools/typescript-fetch-petstore' // TODO: Update the object below with actual values const example = { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/package.json b/samples/client/petstore/typescript-fetch/builds/oneOf/package.json new file mode 100644 index 000000000000..50d947e6258d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/package.json @@ -0,0 +1,22 @@ +{ + "name": "@openapitools/typescript-fetch-petstore", + "version": "1.0.0", + "description": "OpenAPI client for @openapitools/typescript-fetch-petstore", + "author": "OpenAPI-Generator", + "repository": { + "type": "git", + "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" + }, + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "scripts": { + "build": "tsc", + "prepare": "npm run build" + }, + "devDependencies": { + "typescript": "^4.0 || ^5.0" + }, + "publishConfig": { + "registry": "https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/DefaultApi.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/DefaultApi.ts new file mode 100644 index 000000000000..725866801ae3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/DefaultApi.ts @@ -0,0 +1,141 @@ +/* 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 * as runtime from '../runtime'; +import type { + TestArrayResponse, + TestDiscriminatorResponse, + TestResponse, +} from '../models/index'; +import { + TestArrayResponseFromJSON, + TestArrayResponseToJSON, + TestDiscriminatorResponseFromJSON, + TestDiscriminatorResponseToJSON, + TestResponseFromJSON, + TestResponseToJSON, +} from '../models/index'; + +/** + * + */ +export class DefaultApi extends runtime.BaseAPI { + + /** + * Creates request options for test without sending the request + */ + async testRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestResponseFromJSON(jsonValue)); + } + + /** + */ + async test(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testArray without sending the request + */ + async testArrayRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-array`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testArrayRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testArrayRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestArrayResponseFromJSON(jsonValue)); + } + + /** + */ + async testArray(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testArrayRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testDiscriminator without sending the request + */ + async testDiscriminatorRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-discriminator`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testDiscriminatorRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testDiscriminatorRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestDiscriminatorResponseFromJSON(jsonValue)); + } + + /** + */ + async testDiscriminator(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testDiscriminatorRaw(initOverrides); + return await response.value(); + } + +} diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/index.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/index.ts new file mode 100644 index 000000000000..69c44c00fa0d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/apis/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './DefaultApi'; diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/index.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/index.ts new file mode 100644 index 000000000000..bebe8bbbe206 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/index.ts @@ -0,0 +1,5 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './runtime'; +export * from './apis/index'; +export * from './models/index'; diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypes.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypes.ts new file mode 100644 index 000000000000..957e73451efc --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypes.ts @@ -0,0 +1,73 @@ +/* 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 { mapValues } from '../runtime'; +import type { OneOfPrimitiveTypesValue } from './OneOfPrimitiveTypesValue'; +import { + OneOfPrimitiveTypesValueFromJSON, + OneOfPrimitiveTypesValueFromJSONTyped, + OneOfPrimitiveTypesValueToJSON, + OneOfPrimitiveTypesValueToJSONTyped, +} from './OneOfPrimitiveTypesValue'; + +/** + * + * @export + * @interface OneOfPrimitiveTypes + */ +export interface OneOfPrimitiveTypes { + /** + * + * @type {OneOfPrimitiveTypesValue} + * @memberof OneOfPrimitiveTypes + */ + value?: OneOfPrimitiveTypesValue; +} + +/** + * Check if a given object implements the OneOfPrimitiveTypes interface. + */ +export function instanceOfOneOfPrimitiveTypes(value: object): value is OneOfPrimitiveTypes { + return true; +} + +export function OneOfPrimitiveTypesFromJSON(json: any): OneOfPrimitiveTypes { + return OneOfPrimitiveTypesFromJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypes { + if (json == null) { + return json; + } + return { + + 'value': json['value'] == null ? undefined : OneOfPrimitiveTypesValueFromJSON(json['value']), + }; +} + +export function OneOfPrimitiveTypesToJSON(json: any): OneOfPrimitiveTypes { + return OneOfPrimitiveTypesToJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesToJSONTyped(value?: OneOfPrimitiveTypes | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'value': OneOfPrimitiveTypesValueToJSON(value['value']), + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypesValue.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypesValue.ts new file mode 100644 index 000000000000..fd7e076d6f76 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OneOfPrimitiveTypesValue.ts @@ -0,0 +1,98 @@ +/* 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 { TestA } from './TestA'; +import { + instanceOfTestA, + TestAFromJSON, + TestAFromJSONTyped, + TestAToJSON, +} from './TestA'; + +/** + * @type OneOfPrimitiveTypesValue + * + * @export + */ +export type OneOfPrimitiveTypesValue = Array | TestA | boolean | number; + +export function OneOfPrimitiveTypesValueFromJSON(json: any): OneOfPrimitiveTypesValue { + return OneOfPrimitiveTypesValueFromJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesValueFromJSONTyped(json: any, ignoreDiscriminator: boolean): OneOfPrimitiveTypesValue { + if (json == null) { + return json; + } + if (typeof json !== 'object') { + return json; + } + if (instanceOfTestA(json)) { + return TestAFromJSONTyped(json, true); + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'object')) { + if (json.every(item => instanceOfTestA(item))) { + return json.map(value => TestAFromJSONTyped(value, true)); + } + } + return json; + } + if (typeof json === 'boolean') { + return json; + } + if (typeof json === 'number') { + return json; + } + return {} as any; +} + +export function OneOfPrimitiveTypesValueToJSON(json: any): any { + return OneOfPrimitiveTypesValueToJSONTyped(json, false); +} + +export function OneOfPrimitiveTypesValueToJSONTyped(value?: OneOfPrimitiveTypesValue | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (typeof value !== 'object') { + return value; + } + if (instanceOfTestA(value)) { + return TestAToJSON(value as TestA); + } + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'object')) { + if (value.every(item => instanceOfTestA(item))) { + return value.map(value => TestAToJSON(value as TestA)); + } + } + return value; + } + if (typeof value === 'boolean') { + return value; + } + if (typeof value === 'number') { + return value; + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionOne.ts new file mode 100644 index 000000000000..3c0c832ab9ca --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionOne.ts @@ -0,0 +1,76 @@ +/* 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 { mapValues } from '../runtime'; +/** + * + * @export + * @interface OptionOne + */ +export interface OptionOne { + /** + * + * @type {string} + * @memberof OptionOne + */ + discriminatorField: OptionOneDiscriminatorFieldEnum; +} + + +/** + * @export + */ +export const OptionOneDiscriminatorFieldEnum = { + OptionOne: 'optionOne' +} as const; +export type OptionOneDiscriminatorFieldEnum = typeof OptionOneDiscriminatorFieldEnum[keyof typeof OptionOneDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the OptionOne interface. + */ +export function instanceOfOptionOne(value: object): value is OptionOne { + if (!('discriminatorField' in value) || value['discriminatorField'] === undefined) return false; + return true; +} + +export function OptionOneFromJSON(json: any): OptionOne { + return OptionOneFromJSONTyped(json, false); +} + +export function OptionOneFromJSONTyped(json: any, ignoreDiscriminator: boolean): OptionOne { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminatorField'], + }; +} + +export function OptionOneToJSON(json: any): OptionOne { + return OptionOneToJSONTyped(json, false); +} + +export function OptionOneToJSONTyped(value?: OptionOne | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminatorField': value['discriminatorField'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionTwo.ts new file mode 100644 index 000000000000..a6cafacf2ada --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/OptionTwo.ts @@ -0,0 +1,76 @@ +/* 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 { mapValues } from '../runtime'; +/** + * + * @export + * @interface OptionTwo + */ +export interface OptionTwo { + /** + * + * @type {string} + * @memberof OptionTwo + */ + discriminatorField: OptionTwoDiscriminatorFieldEnum; +} + + +/** + * @export + */ +export const OptionTwoDiscriminatorFieldEnum = { + OptionTwo: 'optionTwo' +} as const; +export type OptionTwoDiscriminatorFieldEnum = typeof OptionTwoDiscriminatorFieldEnum[keyof typeof OptionTwoDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the OptionTwo interface. + */ +export function instanceOfOptionTwo(value: object): value is OptionTwo { + if (!('discriminatorField' in value) || value['discriminatorField'] === undefined) return false; + return true; +} + +export function OptionTwoFromJSON(json: any): OptionTwo { + return OptionTwoFromJSONTyped(json, false); +} + +export function OptionTwoFromJSONTyped(json: any, ignoreDiscriminator: boolean): OptionTwo { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminatorField'], + }; +} + +export function OptionTwoToJSON(json: any): OptionTwo { + return OptionTwoToJSONTyped(json, false); +} + +export function OptionTwoToJSONTyped(value?: OptionTwo | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminatorField': value['discriminatorField'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestA.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestA.ts new file mode 100644 index 000000000000..198768099c18 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestA.ts @@ -0,0 +1,66 @@ +/* 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 { mapValues } from '../runtime'; +/** + * + * @export + * @interface TestA + */ +export interface TestA { + /** + * + * @type {string} + * @memberof TestA + */ + foo: string; +} + +/** + * Check if a given object implements the TestA interface. + */ +export function instanceOfTestA(value: object): value is TestA { + if (!('foo' in value) || value['foo'] === undefined) return false; + return true; +} + +export function TestAFromJSON(json: any): TestA { + return TestAFromJSONTyped(json, false); +} + +export function TestAFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestA { + if (json == null) { + return json; + } + return { + + 'foo': json['foo'], + }; +} + +export function TestAToJSON(json: any): TestA { + return TestAToJSONTyped(json, false); +} + +export function TestAToJSONTyped(value?: TestA | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'foo': value['foo'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestArrayResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestArrayResponse.ts new file mode 100644 index 000000000000..29e0eb1017e3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestArrayResponse.ts @@ -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 | Array | Array; + +export function TestArrayResponseFromJSON(json: any): TestArrayResponse { + return TestArrayResponseFromJSONTyped(json, false); +} + +export function TestArrayResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestArrayResponse { + if (json == null) { + return json; + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'object')) { + if (json.every(item => instanceOfTestA(item))) { + return json.map(value => TestAFromJSONTyped(value, true)); + } + if (json.every(item => instanceOfTestB(item))) { + return json.map(value => TestBFromJSONTyped(value, true)); + } + } + return json; + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'string')) { + return json; + } + } + 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 (Array.isArray(value)) { + if (value.every(item => typeof item === 'object')) { + if (value.every(item => instanceOfTestA(item))) { + return value.map(value => TestAToJSON(value as TestA)); + } + if (value.every(item => instanceOfTestB(item))) { + return value.map(value => TestBToJSON(value as TestB)); + } + } + return value; + } + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'string')) { + return value; + } + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestB.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestB.ts new file mode 100644 index 000000000000..f33eae68ab37 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestB.ts @@ -0,0 +1,66 @@ +/* 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 { mapValues } from '../runtime'; +/** + * + * @export + * @interface TestB + */ +export interface TestB { + /** + * + * @type {string} + * @memberof TestB + */ + bar: string; +} + +/** + * Check if a given object implements the TestB interface. + */ +export function instanceOfTestB(value: object): value is TestB { + if (!('bar' in value) || value['bar'] === undefined) return false; + return true; +} + +export function TestBFromJSON(json: any): TestB { + return TestBFromJSONTyped(json, false); +} + +export function TestBFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestB { + if (json == null) { + return json; + } + return { + + 'bar': json['bar'], + }; +} + +export function TestBToJSON(json: any): TestB { + return TestBToJSONTyped(json, false); +} + +export function TestBToJSONTyped(value?: TestB | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'bar': value['bar'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestDiscriminatorResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestDiscriminatorResponse.ts new file mode 100644 index 000000000000..0596cafad7e1 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestDiscriminatorResponse.ts @@ -0,0 +1,72 @@ +/* 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 { OptionOne } from './OptionOne'; +import { + instanceOfOptionOne, + OptionOneFromJSON, + OptionOneFromJSONTyped, + OptionOneToJSON, +} from './OptionOne'; +import type { OptionTwo } from './OptionTwo'; +import { + instanceOfOptionTwo, + OptionTwoFromJSON, + OptionTwoFromJSONTyped, + OptionTwoToJSON, +} from './OptionTwo'; + +/** + * @type TestDiscriminatorResponse + * + * @export + */ +export type TestDiscriminatorResponse = { discriminatorField: 'optionOne' } & OptionOne | { discriminatorField: 'optionTwo' } & OptionTwo; + +export function TestDiscriminatorResponseFromJSON(json: any): TestDiscriminatorResponse { + return TestDiscriminatorResponseFromJSONTyped(json, false); +} + +export function TestDiscriminatorResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestDiscriminatorResponse { + if (json == null) { + return json; + } + switch (json['discriminatorField']) { + case 'optionOne': + return Object.assign({}, OptionOneFromJSONTyped(json, true), { discriminatorField: 'optionOne' } as const); + case 'optionTwo': + return Object.assign({}, OptionTwoFromJSONTyped(json, true), { discriminatorField: 'optionTwo' } as const); + default: + return json; + } +} + +export function TestDiscriminatorResponseToJSON(json: any): any { + return TestDiscriminatorResponseToJSONTyped(json, false); +} + +export function TestDiscriminatorResponseToJSONTyped(value?: TestDiscriminatorResponse | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + switch (value['discriminatorField']) { + case 'optionOne': + return Object.assign({}, OptionOneToJSON(value), { discriminatorField: 'optionOne' } as const); + case 'optionTwo': + return Object.assign({}, OptionTwoToJSON(value), { discriminatorField: 'optionTwo' } as const); + default: + return value; + } +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestResponse.ts new file mode 100644 index 000000000000..031d545e20bc --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/TestResponse.ts @@ -0,0 +1,82 @@ +/* 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 TestResponse + * + * @export + */ +export type TestResponse = TestA | TestB | string; + +export function TestResponseFromJSON(json: any): TestResponse { + return TestResponseFromJSONTyped(json, false); +} + +export function TestResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestResponse { + if (json == null) { + return json; + } + if (typeof json !== 'object') { + return json; + } + if (instanceOfTestA(json)) { + return TestAFromJSONTyped(json, true); + } + if (instanceOfTestB(json)) { + return TestBFromJSONTyped(json, true); + } + if (typeof json === 'string') { + return json; + } + return {} as any; +} + +export function TestResponseToJSON(json: any): any { + return TestResponseToJSONTyped(json, false); +} + +export function TestResponseToJSONTyped(value?: TestResponse | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (typeof value !== 'object') { + return value; + } + if (instanceOfTestA(value)) { + return TestAToJSON(value as TestA); + } + if (instanceOfTestB(value)) { + return TestBToJSON(value as TestB); + } + if (typeof value === 'string') { + return value; + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/index.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/index.ts new file mode 100644 index 000000000000..9ef854f6741c --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/models/index.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './OneOfPrimitiveTypes'; +export * from './OneOfPrimitiveTypesValue'; +export * from './OptionOne'; +export * from './OptionTwo'; +export * from './TestA'; +export * from './TestArrayResponse'; +export * from './TestB'; +export * from './TestDiscriminatorResponse'; +export * from './TestResponse'; diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/src/runtime.ts new file mode 100644 index 000000000000..c807c6354f8d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/src/runtime.ts @@ -0,0 +1,432 @@ +/* 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. + */ + + +export const BASE_PATH = "http://localhost:3000".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i'); + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +export function mapValues(data: any, fn: (item: any) => any) { + const result: { [key: string]: any } = {}; + for (const key of Object.keys(data)) { + result[key] = fn(data[key]); + } + return result; +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if ('multipart/form-data' === consume.contentType) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/tsconfig.json b/samples/client/petstore/typescript-fetch/builds/oneOf/tsconfig.json new file mode 100644 index 000000000000..4567ec19899a --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "declaration": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "dist", + "lib": [ + "es6", + "dom" + ], + "typeRoots": [ + "node_modules/@types" + ] + }, + "exclude": [ + "dist", + "node_modules" + ] +}