OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

[BUG][Typescript] Invalid oneOf strategy in models #18992

Closed ksvirkou-hubspot closed 1 week ago

ksvirkou-hubspot commented 1 week ago
Description

Typescript generator generates new model for oneOf PublicActionDefinitionInputFieldDependenciesInner. It impossible to send proper request to API using this model. PublicActionDefinitionInputFieldDependenciesInner model doesn't contain a field for choosing oneOf's models. The generator version 5.4.0 uses union types: PublicSingleFieldDependency | PublicConditionalSingleFieldDependency. Can I create a PR for returning back to union types? Can I create sample app for testing it?

Output
export class PublicActionDefinition {
    'inputFieldDependencies'?: Array<PublicActionDefinitionInputFieldDependenciesInner>;
}

PublicActionDefinitionInputFieldDependenciesInner model:


import { PublicConditionalSingleFieldDependency } from './publicConditionalSingleFieldDependency';
import { PublicSingleFieldDependency } from './publicSingleFieldDependency';

export class PublicActionDefinitionInputFieldDependenciesInner {
    'dependencyType': PublicActionDefinitionInputFieldDependenciesInner.DependencyTypeEnum = PublicActionDefinitionInputFieldDependenciesInner.DependencyTypeEnum.ConditionalSingleField;
    'dependentFieldNames': Array<string>;
    'controllingFieldName': string;
    'controllingFieldValue': string;
    static discriminator: string | undefined = undefined;

...
}

export namespace PublicActionDefinitionInputFieldDependenciesInner {
    export enum DependencyTypeEnum {
        ConditionalSingleField = <any> 'CONDITIONAL_SINGLE_FIELD'
    }
}

In v 5.4.0

openapi-generator version

6.0.0 or higher

OpenAPI declaration file content or url
"PublicActionDefinition": {
    "properties": {
        "inputFieldDependencies": {
            "type": "array",
            "items": {
                "oneOf": [
                    {
                        "$ref": "#/components/schemas/PublicSingleFieldDependency"
                    },
                    {
                        "$ref": "#/components/schemas/PublicConditionalSingleFieldDependency"
                    }
                ]
            }
        }
    }
}
Generation Details

generate -i *.json -g typescript -o /dir --skip-validate-spec --additional-properties usePromises=true,supportsES6=true,platform=node

Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/11679

Suggest a fix

Can I create a PR for returning back to union types? Can I create sample app for testing oneOf?

ksvirkou-hubspot commented 1 week ago

Can I create a PR for returning back to union types? Can I create sample app for testing oneOf? @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka