From e0cb018b282d8c7b5f58c31ac0ba9ee04675b491 Mon Sep 17 00:00:00 2001 From: Elliott Kember Date: Fri, 24 Oct 2025 07:34:24 +1300 Subject: [PATCH 1/3] Update modelOneOf.mustache Adds booleans to modelOneOf --- .../typescript-fetch/modelOneOf.mustache | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 7d5c01878949..d9a828e42cdb 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache @@ -89,6 +89,13 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole } } {{/isNumeric}} + {{#isBoolean}} + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'boolean'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) { + return json; + } + } + {{/isBoolean}} {{#isString}} if (Array.isArray(json)) { if (json.every(item => typeof item === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) { @@ -116,6 +123,11 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole return json; } {{/isNumeric}} + {{#isBoolean}} + if (typeof json === 'boolean'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) { + return json; + } + {{/isBoolean}} {{#isString}} if (typeof json === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) { return json; @@ -194,6 +206,13 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis } } {{/isNumeric}} + {{#isBoolean}} + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'boolean'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) { + return value; + } + } + {{/isBoolean}} {{#isString}} if (Array.isArray(value)) { if (value.every(item => typeof item === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) { @@ -219,6 +238,11 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis return value; } {{/isNumeric}} + {{#isBoolean}} + if (typeof value === 'boolean'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) { + return value; + } + {{/isBoolean}} {{#isString}} if (typeof value === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) { return value; From 15ffa561233d4330c366d3d135767ff95fd38cb2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 27 Oct 2025 13:53:01 +0800 Subject: [PATCH 2/3] add tests for oneof primitive types --- .../resources/3_0/typescript-fetch/oneOf.yaml | 7 ++- .../builds/oneOf/.openapi-generator/FILES | 2 + .../builds/oneOf/docs/VariousOneOf.md | 32 ++++++++++ .../builds/oneOf/models/VariousOneOf.ts | 61 +++++++++++++++++++ .../builds/oneOf/models/index.ts | 1 + 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/docs/VariousOneOf.md create mode 100644 samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.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..b93f439914fa 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,9 @@ components: - "optionTwo" type: string required: - - discriminatorField \ No newline at end of file + - discriminatorField + VariousOneOf: + oneOf: + - type: string + - type: integer + - type: boolean 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..e6d3a71ffa82 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/.openapi-generator/FILES @@ -8,6 +8,7 @@ docs/TestArrayResponse.md docs/TestB.md docs/TestDiscriminatorResponse.md docs/TestResponse.md +docs/VariousOneOf.md index.ts models/OptionOne.ts models/OptionTwo.ts @@ -16,5 +17,6 @@ models/TestArrayResponse.ts models/TestB.ts models/TestDiscriminatorResponse.ts models/TestResponse.ts +models/VariousOneOf.ts models/index.ts runtime.ts diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/docs/VariousOneOf.md b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/VariousOneOf.md new file mode 100644 index 000000000000..eb78d9f4139f --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/docs/VariousOneOf.md @@ -0,0 +1,32 @@ + +# VariousOneOf + + +## Properties + +Name | Type +------------ | ------------- + +## Example + +```typescript +import type { VariousOneOf } from '' + +// TODO: Update the object below with actual values +const example = { +} satisfies VariousOneOf + +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 VariousOneOf +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/VariousOneOf.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts new file mode 100644 index 000000000000..96c5a03d2731 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts @@ -0,0 +1,61 @@ +/* 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. + */ + +/** + * @type VariousOneOf + * + * @export + */ +export type VariousOneOf = boolean | number | string; + +export function VariousOneOfFromJSON(json: any): VariousOneOf { + return VariousOneOfFromJSONTyped(json, false); +} + +export function VariousOneOfFromJSONTyped(json: any, ignoreDiscriminator: boolean): VariousOneOf { + if (json == null) { + return json; + } + if (typeof json === 'boolean') { + return json; + } + if (typeof json === 'number') { + return json; + } + if (typeof json === 'string') { + return json; + } + return {} as any; +} + +export function VariousOneOfToJSON(json: any): any { + return VariousOneOfToJSONTyped(json, false); +} + +export function VariousOneOfToJSONTyped(value?: VariousOneOf | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (typeof value === 'boolean') { + return value; + } + if (typeof value === 'number') { + return value; + } + if (typeof value === 'string') { + 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..425b97cbcb6f 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/index.ts @@ -7,3 +7,4 @@ export * from './TestArrayResponse'; export * from './TestB'; export * from './TestDiscriminatorResponse'; export * from './TestResponse'; +export * from './VariousOneOf'; From fc9b99c237c1eaacf6f89a49804a3435f89bd774 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 27 Oct 2025 14:04:17 +0800 Subject: [PATCH 3/3] trigger build failure --- .../typescript-fetch/builds/oneOf/models/VariousOneOf.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts index 96c5a03d2731..8ab562524325 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/VariousOneOf.ts @@ -1,3 +1,5 @@ +sdklfj;aklsdjf;ajsdkl + /* tslint:disable */ /* eslint-disable */ /**