From f20503964585e30b65a01d9cd213777fbc8a2441 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Fri, 26 Apr 2024 17:07:10 +0300 Subject: [PATCH 1/8] Add enum type generator argument --- .../languages/TypeScriptClientCodegen.java | 19 +++++++++++++++++++ .../resources/typescript/model/model.mustache | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index 4e78a623b0e7..d843c4565f94 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -74,6 +74,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters"; private static final String USE_OBJECT_PARAMS_DESC = "Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument."; + private static final String ENUM_TYPE_SWITCH = "enumType"; + private static final String ENUM_TYPE_SWITCH_DESC = "Specify the enum type which should be used in the client code."; + private static final String[] ENUM_TYPES = {"stringUnion", "enum"}; private final Map frameworkToHttpLibMap; @@ -135,6 +138,13 @@ public TypeScriptClientCodegen() { cliOptions.add(platformOption); + CliOption enumTypeOption = new CliOption(TypeScriptClientCodegen.ENUM_TYPE_SWITCH, TypeScriptClientCodegen.ENUM_TYPE_SWITCH_DESC); + for (String option : TypeScriptClientCodegen.ENUM_TYPES) { + enumTypeOption.addEnum(option, option); + } + enumTypeOption.defaultValue(ENUM_TYPES[0]); + cliOptions.add(enumTypeOption); + // Set property naming to camelCase supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); @@ -426,6 +436,15 @@ public void processOpts() { "http", httpLibName + ".ts" )); + additionalProperties.putIfAbsent(ENUM_TYPE_SWITCH, ENUM_TYPES[0]); + Object propEnumType = additionalProperties.get(ENUM_TYPE_SWITCH); + + Map enumTypes = new HashMap<>(); + for (String enumType : ENUM_TYPES) { + enumTypes.put(enumType, enumType.equals(propEnumType)); + } + additionalProperties.put("enumTypes", enumTypes); + Object propPlatform = additionalProperties.get(PLATFORM_SWITCH); if (propPlatform == null) { propPlatform = "browser"; diff --git a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache index 798297cba063..33d22d33993c 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache @@ -71,6 +71,8 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{#vars}} {{#isEnum}} +{{#enumTypes}} +{{#enum}} export enum {{classname}}{{enumName}} { {{#allowableValues}} {{#enumVars}} @@ -78,12 +80,19 @@ export enum {{classname}}{{enumName}} { {{/enumVars}} {{/allowableValues}} } +{{/enum}} +{{#stringUnion}} + export type {{classname}}{{enumName}} ={{#allowableValues}}{{#values}} "{{.}}" {{^-last}}|{{/-last}}{{/values}}{{/allowableValues}}; +{{/stringUnion}} +{{/enumTypes}} {{/isEnum}} {{/vars}} {{/hasEnums}} {{/isEnum}} {{#isEnum}} +{{#enumTypes}} +{{#enum}} export enum {{classname}} { {{#allowableValues}} {{#enumVars}} @@ -91,6 +100,11 @@ export enum {{classname}} { {{/enumVars}} {{/allowableValues}} } +{{/enum}} +{{#stringUnion}} + export type {{classname}} ={{#allowableValues}}{{#values}} "{{.}}" {{^-last}}|{{/-last}}{{/values}}{{/allowableValues}}; +{{/stringUnion}} +{{/enumTypes}} {{/isEnum}} {{/model}} {{/models}} \ No newline at end of file From bccad7983987769d7b8b82cbc508b083b8b47050 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Fri, 26 Apr 2024 17:09:21 +0300 Subject: [PATCH 2/8] Generate tests --- .../petstore/typescript/builds/browser/models/Order.ts | 6 +----- .../petstore/typescript/builds/browser/models/Pet.ts | 6 +----- .../typescript/builds/composed-schemas/models/Dog.ts | 7 +------ .../typescript/builds/composed-schemas/models/PetByType.ts | 5 +---- .../composed-schemas/models/PetsFilteredPatchRequest.ts | 5 +---- .../builds/composed-schemas/models/PetsPatchRequest.ts | 7 +------ .../petstore/typescript/builds/default/models/Order.ts | 6 +----- .../petstore/typescript/builds/default/models/Pet.ts | 6 +----- .../client/petstore/typescript/builds/deno/models/Order.ts | 6 +----- .../client/petstore/typescript/builds/deno/models/Pet.ts | 6 +----- .../petstore/typescript/builds/inversify/models/Order.ts | 6 +----- .../petstore/typescript/builds/inversify/models/Pet.ts | 6 +----- .../petstore/typescript/builds/jquery/models/Order.ts | 6 +----- .../client/petstore/typescript/builds/jquery/models/Pet.ts | 6 +----- .../typescript/builds/object_params/models/Order.ts | 6 +----- .../petstore/typescript/builds/object_params/models/Pet.ts | 6 +----- 16 files changed, 16 insertions(+), 80 deletions(-) diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts index 4d83c9db7549..f0ad507f24bf 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts @@ -41,10 +41,5 @@ export class Dog { } -export enum DogBreedEnum { - Dingo = 'Dingo', - Husky = 'Husky', - Retriever = 'Retriever', - Shepherd = 'Shepherd' -} + export type DogBreedEnum = "Dingo" | "Husky" | "Retriever" | "Shepherd" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts index 4306e8ead938..67f38514cfd5 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts @@ -41,8 +41,5 @@ export class PetByType { } -export enum PetByTypePetTypeEnum { - Cat = 'Cat', - Dog = 'Dog' -} + export type PetByTypePetTypeEnum = "Cat" | "Dog" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts index 4eaec36a60c6..371bc5b7878e 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts @@ -57,8 +57,5 @@ export class PetsFilteredPatchRequest { } -export enum PetsFilteredPatchRequestPetTypeEnum { - Cat = 'Cat', - Dog = 'Dog' -} + export type PetsFilteredPatchRequestPetTypeEnum = "Cat" | "Dog" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts index 7c1009e3d515..2db81f2e28a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts @@ -58,10 +58,5 @@ export class PetsPatchRequest { } -export enum PetsPatchRequestBreedEnum { - Dingo = 'Dingo', - Husky = 'Husky', - Retriever = 'Retriever', - Shepherd = 'Shepherd' -} + export type PetsPatchRequestBreedEnum = "Dingo" | "Husky" | "Retriever" | "Shepherd" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts index 63e6b8fe3f12..de026e8068a9 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts index 1404661b6de0..a028c6923692 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; From 2b7dd09decb3030070aeafe0e02970f6803028b9 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Fri, 26 Apr 2024 17:28:02 +0300 Subject: [PATCH 3/8] fix default sample test --- .../petstore/typescript/tests/default/test/api/PetApi.test.ts | 2 +- .../tests/default/test/models/ObjectSerializer.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts index 2b215ee28aea..8f511cc1d3f7 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts @@ -18,7 +18,7 @@ describe("PetApi", () => { pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] - pet.status = petstore.PetStatusEnum.Available + pet.status = "available" pet.tags = [ tag ] await petApi.addPet(pet); diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts index c0a2be85466f..800f04b2f5b1 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts @@ -92,7 +92,7 @@ describe("ObjectSerializer", () => { pet.category = category pet.name = "PetName" pet.photoUrls = [ "url", "other url"] - pet.status = petstore.PetStatusEnum.Available + pet.status = "available" pet.tags = tags expect(ObjectSerializer.serialize(pet, "Pet", "")).to.deep.equal({ @@ -199,7 +199,7 @@ describe("ObjectSerializer", () => { pet.category = category pet.name = "PetName" pet.photoUrls = [ "url", "other url"] - pet.status = petstore.PetStatusEnum.Available + pet.status = "available" pet.tags = tags const deserialized = ObjectSerializer.deserialize({ From 43d7ae46ef388cc71dd4e4364ad1147b7cf8eea9 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Mon, 29 Apr 2024 11:47:44 +0300 Subject: [PATCH 4/8] Fix all typescript tests --- .../petstore/typescript/tests/browser/test/PetApi.test.ts | 4 ++-- .../petstore/typescript/tests/default/test/api/PetApi.test.ts | 2 +- .../petstore/typescript/tests/deno/test/api/PetApi_test.ts | 2 +- .../petstore/typescript/tests/jquery/test/api/PetApi.test.ts | 2 +- .../typescript/tests/object_params/test/api/PetApi.test.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/openapi3/client/petstore/typescript/tests/browser/test/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/browser/test/PetApi.test.ts index 88e0a850894f..a4334fe7457a 100644 --- a/samples/openapi3/client/petstore/typescript/tests/browser/test/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/browser/test/PetApi.test.ts @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import { ServerConfiguration, createConfiguration, PetApi, Tag, Pet, PetStatusEnum, ApiException, RequiredError } from 'ts-petstore-client' +import { ServerConfiguration, createConfiguration, PetApi, Tag, Pet, ApiException, RequiredError } from 'ts-petstore-client' import image from "./pet"; const configuration = createConfiguration({ @@ -20,7 +20,7 @@ function createPet() { pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] - pet.status = PetStatusEnum.Available + pet.status = 'available' pet.tags = [ tag ] return pet as Required; } diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts index 8f511cc1d3f7..dd6cfbc3763c 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts @@ -18,7 +18,7 @@ describe("PetApi", () => { pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] - pet.status = "available" + pet.status = 'available' pet.tags = [ tag ] await petApi.addPet(pet); diff --git a/samples/openapi3/client/petstore/typescript/tests/deno/test/api/PetApi_test.ts b/samples/openapi3/client/petstore/typescript/tests/deno/test/api/PetApi_test.ts index 9b8e652ce76b..4025e670597f 100644 --- a/samples/openapi3/client/petstore/typescript/tests/deno/test/api/PetApi_test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/deno/test/api/PetApi_test.ts @@ -17,7 +17,7 @@ const petId = Math.floor(Math.random() * 100000); pet.id = petId; pet.name = "PetName"; pet.photoUrls = []; -pet.status = petstore.PetStatusEnum.Available; +pet.status = 'available'; pet.tags = [tag]; Deno.test({ diff --git a/samples/openapi3/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts index b061610023ca..ef3882f9e573 100644 --- a/samples/openapi3/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/jquery/test/api/PetApi.test.ts @@ -16,7 +16,7 @@ const pet = new petstore.Pet() pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] -pet.status = petstore.PetStatusEnum.Available +pet.status = 'available' pet.tags = [ tag ] QUnit.module("PetApi") diff --git a/samples/openapi3/client/petstore/typescript/tests/object_params/test/api/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/object_params/test/api/PetApi.test.ts index 2e2c311634da..302304492bbc 100644 --- a/samples/openapi3/client/petstore/typescript/tests/object_params/test/api/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/object_params/test/api/PetApi.test.ts @@ -15,7 +15,7 @@ const pet = new petstore.Pet() pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] -pet.status = petstore.PetStatusEnum.Available +pet.status = 'available' pet.tags = [ tag ] describe("PetApi", () =>{ From 3a630f25345de3f1bc049a069d8cd3c7ce10fc87 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Mon, 29 Apr 2024 12:10:41 +0300 Subject: [PATCH 5/8] Update docs --- docs/generators/typescript.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index ed7612a0cea4..98653cbe51ca 100644 --- a/docs/generators/typescript.md +++ b/docs/generators/typescript.md @@ -24,6 +24,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| |enumPropertyNamingReplaceSpecialChar|Set to true to replace '-' and '+' symbols with 'minus_' and 'plus_' in enum of type string| |false| +|enumType|Specify the enum type which should be used in the client code.|
**stringUnion**
stringUnion
**enum**
enum
|stringUnion| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser, Deno) / Buffer (node)| |Buffer| |framework|Specify the framework which should be used in the client code.|
**fetch-api**
fetch-api
**jquery**
jquery
|fetch-api| From 251cf574fce71272dcdad1efc972e920d9031b9a Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Mon, 29 Apr 2024 18:03:02 +0300 Subject: [PATCH 6/8] Added description for enum types --- docs/generators/typescript.md | 2 +- .../codegen/languages/TypeScriptClientCodegen.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index 98653cbe51ca..ff0447769b12 100644 --- a/docs/generators/typescript.md +++ b/docs/generators/typescript.md @@ -24,7 +24,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| |enumPropertyNamingReplaceSpecialChar|Set to true to replace '-' and '+' symbols with 'minus_' and 'plus_' in enum of type string| |false| -|enumType|Specify the enum type which should be used in the client code.|
**stringUnion**
stringUnion
**enum**
enum
|stringUnion| +|enumType|Specify the enum type which should be used in the client code.|
**stringUnion**
Union of literal string types
**enum**
Typescript's [string enums](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums)
|stringUnion| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser, Deno) / Buffer (node)| |Buffer| |framework|Specify the framework which should be used in the client code.|
**fetch-api**
fetch-api
**jquery**
jquery
|fetch-api| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index d843c4565f94..9b79b98b71a2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -76,7 +76,7 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp private static final String USE_OBJECT_PARAMS_DESC = "Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument."; private static final String ENUM_TYPE_SWITCH = "enumType"; private static final String ENUM_TYPE_SWITCH_DESC = "Specify the enum type which should be used in the client code."; - private static final String[] ENUM_TYPES = {"stringUnion", "enum"}; + private static final String[][] ENUM_TYPES = {{"stringUnion", "Union of literal string types"}, {"enum", "Typescript's [string enums](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums)"}}; private final Map frameworkToHttpLibMap; @@ -139,10 +139,10 @@ public TypeScriptClientCodegen() { cliOptions.add(platformOption); CliOption enumTypeOption = new CliOption(TypeScriptClientCodegen.ENUM_TYPE_SWITCH, TypeScriptClientCodegen.ENUM_TYPE_SWITCH_DESC); - for (String option : TypeScriptClientCodegen.ENUM_TYPES) { - enumTypeOption.addEnum(option, option); + for (String[] option : TypeScriptClientCodegen.ENUM_TYPES) { + enumTypeOption.addEnum(option[0], option[1]); } - enumTypeOption.defaultValue(ENUM_TYPES[0]); + enumTypeOption.defaultValue(ENUM_TYPES[0][0]); cliOptions.add(enumTypeOption); // Set property naming to camelCase @@ -440,8 +440,8 @@ public void processOpts() { Object propEnumType = additionalProperties.get(ENUM_TYPE_SWITCH); Map enumTypes = new HashMap<>(); - for (String enumType : ENUM_TYPES) { - enumTypes.put(enumType, enumType.equals(propEnumType)); + for (String[] enumType : ENUM_TYPES) { + enumTypes.put(enumType[0], enumType.equals(propEnumType)); } additionalProperties.put("enumTypes", enumTypes); From 632f89691b6387ce53ca1d7bc3391531b753124c Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Mon, 20 May 2024 12:19:50 +0300 Subject: [PATCH 7/8] Set enum type as default --- docs/generators/typescript.md | 2 +- .../languages/TypeScriptClientCodegen.java | 8 ++++---- .../typescript/builds/browser/models/Order.ts | 6 +++++- .../typescript/builds/browser/models/Pet.ts | 6 +++++- .../builds/composed-schemas/models/Dog.ts | 7 ++++++- .../builds/composed-schemas/models/PetByType.ts | 5 ++++- .../models/PetsFilteredPatchRequest.ts | 5 ++++- .../composed-schemas/models/PetsPatchRequest.ts | 7 ++++++- .../typescript/builds/default/models/Order.ts | 6 +++++- .../typescript/builds/default/models/Pet.ts | 6 +++++- .../typescript/builds/deno/models/Order.ts | 6 +++++- .../typescript/builds/deno/models/Pet.ts | 6 +++++- .../typescript/builds/inversify/models/Order.ts | 6 +++++- .../typescript/builds/inversify/models/Pet.ts | 6 +++++- .../typescript/builds/jquery/models/Order.ts | 6 +++++- .../typescript/builds/jquery/models/Pet.ts | 6 +++++- .../builds/object_params/models/Order.ts | 6 +++++- .../builds/object_params/models/Pet.ts | 6 +++++- .../tests/default/test/api/PetApi.test.ts | 2 +- .../default/test/models/ObjectSerializer.test.ts | 16 ++++++++-------- 20 files changed, 94 insertions(+), 30 deletions(-) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index ff0447769b12..d2c8464eca9a 100644 --- a/docs/generators/typescript.md +++ b/docs/generators/typescript.md @@ -24,7 +24,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| |enumPropertyNamingReplaceSpecialChar|Set to true to replace '-' and '+' symbols with 'minus_' and 'plus_' in enum of type string| |false| -|enumType|Specify the enum type which should be used in the client code.|
**stringUnion**
Union of literal string types
**enum**
Typescript's [string enums](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums)
|stringUnion| +|enumType|Specify the enum type which should be used in the client code.|
**stringUnion**
Union of literal string types
**enum**
Typescript's [string enums](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums)
|enum| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| |fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser, Deno) / Buffer (node)| |Buffer| |framework|Specify the framework which should be used in the client code.|
**fetch-api**
fetch-api
**jquery**
jquery
|fetch-api| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index 9b79b98b71a2..e22cb70cdae3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -142,7 +142,7 @@ public TypeScriptClientCodegen() { for (String[] option : TypeScriptClientCodegen.ENUM_TYPES) { enumTypeOption.addEnum(option[0], option[1]); } - enumTypeOption.defaultValue(ENUM_TYPES[0][0]); + enumTypeOption.defaultValue(ENUM_TYPES[1][0]); cliOptions.add(enumTypeOption); // Set property naming to camelCase @@ -436,12 +436,12 @@ public void processOpts() { "http", httpLibName + ".ts" )); - additionalProperties.putIfAbsent(ENUM_TYPE_SWITCH, ENUM_TYPES[0]); + additionalProperties.putIfAbsent(ENUM_TYPE_SWITCH, ENUM_TYPES[1][0]); Object propEnumType = additionalProperties.get(ENUM_TYPE_SWITCH); Map enumTypes = new HashMap<>(); - for (String[] enumType : ENUM_TYPES) { - enumTypes.put(enumType[0], enumType.equals(propEnumType)); + for (String[] option : ENUM_TYPES) { + enumTypes.put(option[0], option[0].equals(propEnumType)); } additionalProperties.put("enumTypes", enumTypes); diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts index 4e9543bf72f6..4d80550bb2af 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts index b52f8f669ef7..ecaefffea4ff 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts index f0ad507f24bf..4d83c9db7549 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Dog.ts @@ -41,5 +41,10 @@ export class Dog { } - export type DogBreedEnum = "Dingo" | "Husky" | "Retriever" | "Shepherd" ; +export enum DogBreedEnum { + Dingo = 'Dingo', + Husky = 'Husky', + Retriever = 'Retriever', + Shepherd = 'Shepherd' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts index 67f38514cfd5..4306e8ead938 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByType.ts @@ -41,5 +41,8 @@ export class PetByType { } - export type PetByTypePetTypeEnum = "Cat" | "Dog" ; +export enum PetByTypePetTypeEnum { + Cat = 'Cat', + Dog = 'Dog' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts index 371bc5b7878e..4eaec36a60c6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsFilteredPatchRequest.ts @@ -57,5 +57,8 @@ export class PetsFilteredPatchRequest { } - export type PetsFilteredPatchRequestPetTypeEnum = "Cat" | "Dog" ; +export enum PetsFilteredPatchRequestPetTypeEnum { + Cat = 'Cat', + Dog = 'Dog' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts index 2db81f2e28a1..7c1009e3d515 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetsPatchRequest.ts @@ -58,5 +58,10 @@ export class PetsPatchRequest { } - export type PetsPatchRequestBreedEnum = "Dingo" | "Husky" | "Retriever" | "Shepherd" ; +export enum PetsPatchRequestBreedEnum { + Dingo = 'Dingo', + Husky = 'Husky', + Retriever = 'Retriever', + Shepherd = 'Shepherd' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts index 4e9543bf72f6..4d80550bb2af 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts index b52f8f669ef7..ecaefffea4ff 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts index de026e8068a9..63e6b8fe3f12 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts index a028c6923692..1404661b6de0 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts index 4e9543bf72f6..4d80550bb2af 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts index b52f8f669ef7..ecaefffea4ff 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts index 4e9543bf72f6..4d80550bb2af 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts index b52f8f669ef7..ecaefffea4ff 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts index 4e9543bf72f6..4d80550bb2af 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts @@ -75,5 +75,9 @@ export class Order { } - export type OrderStatusEnum = "placed" | "approved" | "delivered" ; +export enum OrderStatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' +} diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts index b52f8f669ef7..ecaefffea4ff 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts @@ -77,5 +77,9 @@ export class Pet { } - export type PetStatusEnum = "available" | "pending" | "sold" ; +export enum PetStatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' +} diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts index dd6cfbc3763c..2b215ee28aea 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/api/PetApi.test.ts @@ -18,7 +18,7 @@ describe("PetApi", () => { pet.id = Math.floor(Math.random() * 100000) pet.name = "PetName" pet.photoUrls = [] - pet.status = 'available' + pet.status = petstore.PetStatusEnum.Available pet.tags = [ tag ] await petApi.addPet(pet); diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts index 800f04b2f5b1..c152f5cdc6f6 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/models/ObjectSerializer.test.ts @@ -66,8 +66,8 @@ describe("ObjectSerializer", () => { }); it ("Enum", () => { - const input = "available" - expect(ObjectSerializer.serialize(input, "Pet.StatusEnum", "")).to.equal("available") + const input = petstore.PetStatusEnum.Available + expect(ObjectSerializer.serialize(input, "Pet.StatusEnum", "")).to.equal(petstore.PetStatusEnum.Available) }) it("Complex Class", () => { @@ -92,7 +92,7 @@ describe("ObjectSerializer", () => { pet.category = category pet.name = "PetName" pet.photoUrls = [ "url", "other url"] - pet.status = "available" + pet.status = petstore.PetStatusEnum.Available pet.tags = tags expect(ObjectSerializer.serialize(pet, "Pet", "")).to.deep.equal({ @@ -103,7 +103,7 @@ describe("ObjectSerializer", () => { "name": category.name }, "photoUrls": [ "url", "other url"], - "status": "available", + "status": petstore.PetStatusEnum.Available, "tags": tagResult }) }) @@ -173,8 +173,8 @@ describe("ObjectSerializer", () => { }); it ("Enum", () => { - const input = "available" - expect(ObjectSerializer.deserialize("available", "Pet.StatusEnum", "")).to.equal(input) + const input = petstore.PetStatusEnum.Available + expect(ObjectSerializer.deserialize(petstore.PetStatusEnum.Available, "Pet.StatusEnum", "")).to.equal(input) }) it("Complex Class", () => { @@ -199,7 +199,7 @@ describe("ObjectSerializer", () => { pet.category = category pet.name = "PetName" pet.photoUrls = [ "url", "other url"] - pet.status = "available" + pet.status = petstore.PetStatusEnum.Available pet.tags = tags const deserialized = ObjectSerializer.deserialize({ @@ -210,7 +210,7 @@ describe("ObjectSerializer", () => { "name": category.name }, "photoUrls": [ "url", "other url"], - "status": "available", + "status": petstore.PetStatusEnum.Available, "tags": tagResult }, "Pet", "") as petstore.Pet From 3f7c03a333ed409e8dd0a0117a2a265ec686ba1f Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Mon, 20 May 2024 12:27:59 +0300 Subject: [PATCH 8/8] Set addition param for all tests except --- bin/configs/typescript-consolidated-browser.yaml | 1 + bin/configs/typescript-consolidated-deno.yaml | 1 + bin/configs/typescript-consolidated-jquery.yaml | 1 + .../typescript-consolidated-node-object-parameters.yaml | 1 + .../petstore/typescript/builds/browser/models/Order.ts | 6 +----- .../client/petstore/typescript/builds/browser/models/Pet.ts | 6 +----- .../client/petstore/typescript/builds/deno/models/Order.ts | 6 +----- .../client/petstore/typescript/builds/deno/models/Pet.ts | 6 +----- .../petstore/typescript/builds/jquery/models/Order.ts | 6 +----- .../client/petstore/typescript/builds/jquery/models/Pet.ts | 6 +----- .../typescript/builds/object_params/models/Order.ts | 6 +----- .../petstore/typescript/builds/object_params/models/Pet.ts | 6 +----- 12 files changed, 12 insertions(+), 40 deletions(-) diff --git a/bin/configs/typescript-consolidated-browser.yaml b/bin/configs/typescript-consolidated-browser.yaml index 8ea49d065b2b..056c50b36d04 100644 --- a/bin/configs/typescript-consolidated-browser.yaml +++ b/bin/configs/typescript-consolidated-browser.yaml @@ -8,3 +8,4 @@ additionalProperties: projectName: ts-petstore-client moduleName: petstore supportsES6: true + enumType: stringUnion diff --git a/bin/configs/typescript-consolidated-deno.yaml b/bin/configs/typescript-consolidated-deno.yaml index b33178846090..eabb31a42916 100644 --- a/bin/configs/typescript-consolidated-deno.yaml +++ b/bin/configs/typescript-consolidated-deno.yaml @@ -7,3 +7,4 @@ additionalProperties: npmName: ts-petstore-client projectName: ts-petstore-client moduleName: petstore + enumType: stringUnion diff --git a/bin/configs/typescript-consolidated-jquery.yaml b/bin/configs/typescript-consolidated-jquery.yaml index 7e9669984c20..ceac9a204c91 100644 --- a/bin/configs/typescript-consolidated-jquery.yaml +++ b/bin/configs/typescript-consolidated-jquery.yaml @@ -7,3 +7,4 @@ additionalProperties: npmName: ts-petstore-client projectName: ts-petstore-client moduleName: petstore + enumType: stringUnion diff --git a/bin/configs/typescript-consolidated-node-object-parameters.yaml b/bin/configs/typescript-consolidated-node-object-parameters.yaml index 5e4e13a7ec73..d7f391bf5b0b 100644 --- a/bin/configs/typescript-consolidated-node-object-parameters.yaml +++ b/bin/configs/typescript-consolidated-node-object-parameters.yaml @@ -8,3 +8,4 @@ additionalProperties: useObjectParameters: true projectName: ts-petstore-client moduleName: petstore + enumType: stringUnion diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts index 63e6b8fe3f12..de026e8068a9 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts index 1404661b6de0..a028c6923692 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts index 4d80550bb2af..4e9543bf72f6 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Order.ts @@ -75,9 +75,5 @@ export class Order { } -export enum OrderStatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' -} + export type OrderStatusEnum = "placed" | "approved" | "delivered" ; diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts index ecaefffea4ff..b52f8f669ef7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts @@ -77,9 +77,5 @@ export class Pet { } -export enum PetStatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' -} + export type PetStatusEnum = "available" | "pending" | "sold" ;