diff --git a/bin/configs/typescript-consolidated-enums.yaml b/bin/configs/typescript-consolidated-enums.yaml deleted file mode 100644 index 0efd114ae30..00000000000 --- a/bin/configs/typescript-consolidated-enums.yaml +++ /dev/null @@ -1,9 +0,0 @@ -generatorName: typescript -outputDir: samples/openapi3/client/petstore/typescript/builds/enum -inputSpec: modules/openapi-generator/src/test/resources/3_0/enum_mapping_test.yaml -templateDir: modules/openapi-generator/src/main/resources/typescript -additionalProperties: - platform: deno - npmName: ts-petstore-client - projectName: ts-petstore-client - moduleName: petstore 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 a07142fa1ff..972afec7f21 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 @@ -354,6 +354,16 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp } } } + if (!cm.oneOf.isEmpty()) { + // For oneOfs only import $refs within the oneOf + TreeSet oneOfRefs = new TreeSet<>(); + for (String im : cm.imports) { + if (cm.oneOf.contains(im)) { + oneOfRefs.add(im); + } + } + cm.imports = oneOfRefs; + } } for (ModelMap mo : models) { CodegenModel cm = mo.getModel(); diff --git a/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache index d84cdec5ff8..f08a7af94f3 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache @@ -6,7 +6,7 @@ export * from '{{{ importPath }}}{{importFileExtension}}'; {{#models}} {{#model}} -import { {{classname}}{{#hasEnums}}{{#vars}}{{#isEnum}}, {{classname}}{{enumName}} {{/isEnum}} {{/vars}}{{/hasEnums}} } from '{{{ importPath }}}{{importFileExtension}}'; +import { {{classname}}{{#oneOf}}{{#-first}}Class{{/-first}}{{/oneOf}}{{^oneOf}}{{#hasEnums}}{{#vars}}{{#isEnum}}, {{classname}}{{enumName}} {{/isEnum}} {{/vars}}{{/hasEnums}}{{/oneOf}} } from '{{{ importPath }}}{{importFileExtension}}'; {{/model}} {{/models}} @@ -43,7 +43,7 @@ let typeMap: {[index: string]: any} = { {{#models}} {{#model}} {{^isEnum}} - "{{classname}}": {{classname}}, + "{{classname}}": {{classname}}{{#oneOf}}{{#-first}}Class{{/-first}}{{/oneOf}}, {{/isEnum}} {{/model}} {{/models}} @@ -125,8 +125,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 b190fadefb0..4f30fea765b 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache @@ -12,6 +12,10 @@ import { HttpFile } from '../http/http{{importFileExtension}}'; */ {{/description}} {{^isEnum}} +{{#oneOf}} +{{#-first}}{{>model/modelOneOf}}{{/-first}} +{{/oneOf}} +{{^oneOf}} export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{#vars}} {{#description}} @@ -28,6 +32,18 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{^discriminator}} static readonly discriminator: string | undefined = undefined; {{/discriminator}} + {{#hasDiscriminatorWithNonEmptyMapping}} + + static readonly mapping: {[index: string]: string} | undefined = { + {{#discriminator.mappedModels}} + "{{mappingName}}": "{{modelName}}", + {{/discriminator.mappedModels}} + }; + {{/hasDiscriminatorWithNonEmptyMapping}} + {{^hasDiscriminatorWithNonEmptyMapping}} + + static readonly mapping: {[index: string]: string} | undefined = undefined; + {{/hasDiscriminatorWithNonEmptyMapping}} {{^isArray}} static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ @@ -62,13 +78,10 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{/discriminatorValue}} {{/allVars}} {{#discriminatorName}} - {{^discriminator.isEnum}} this.{{discriminatorName}} = "{{classname}}"; - {{/discriminator.isEnum}} {{/discriminatorName}} } } - {{#hasEnums}} {{#vars}} @@ -84,6 +97,7 @@ export enum {{classname}}{{enumName}} { {{/vars}} {{/hasEnums}} +{{/oneOf}} {{/isEnum}} {{#isEnum}} export enum {{classname}} { diff --git a/modules/openapi-generator/src/main/resources/typescript/model/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript/model/modelOneOf.mustache new file mode 100644 index 00000000000..d5e026ac6d4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/model/modelOneOf.mustache @@ -0,0 +1,40 @@ +{{#hasImports}} +import { + {{#imports}} + {{{.}}}{{importFileExtension}}, + {{/imports}} +} from './'; + +{{/hasImports}} +/** + * @type {{classname}} + * Type + * @export + */ +export type {{classname}} = {{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}}; + +/** +* @type {{classname}}Class{{#description}} + * {{{.}}}{{/description}} +* @export +*/ +export class {{classname}}Class { + {{#discriminator}} + static readonly discriminator: string | undefined = "{{discriminatorName}}"; + {{/discriminator}} + {{^discriminator}} + static readonly discriminator: string | undefined = undefined; + {{/discriminator}} + {{#hasDiscriminatorWithNonEmptyMapping}} + + static readonly mapping: {[index: string]: string} | undefined = { + {{#discriminator.mappedModels}} + "{{mappingName}}": "{{modelName}}", + {{/discriminator.mappedModels}} + }; + {{/hasDiscriminatorWithNonEmptyMapping}} + {{^hasDiscriminatorWithNonEmptyMapping}} + + static readonly mapping: {[index: string]: string} | undefined = undefined; + {{/hasDiscriminatorWithNonEmptyMapping}} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_0/enum_mapping_test.yaml b/modules/openapi-generator/src/test/resources/3_0/enum_mapping_test.yaml deleted file mode 100644 index 82741c83533..00000000000 --- a/modules/openapi-generator/src/test/resources/3_0/enum_mapping_test.yaml +++ /dev/null @@ -1,77 +0,0 @@ -openapi: 3.0.0 -info: - title: Sample API to test enum mapping - description: API description in Markdown. - version: 1.0.0 -paths: - /interactions: - get: - summary: Returns all interactions. - description: Optional extended description in Markdown. - parameters: - - in: query - name: parameter_type_mapping - schema: - type: string - format: special - responses: - 200: - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/Interaction' -components: - schemas: - ChatMessage: - type: "object" - properties: - type: - description: "The type of interaction" - enum: - - "chat-message" - example: "chat-message" - type: "string" - message: - description: "The message content" - type: "string" - example: "Hello, how are you?" - Email: - type: "object" - properties: - type: - description: "The type of interaction" - enum: - - "email" - example: "email" - type: "string" - subject: - description: "The email subject" - type: "string" - example: "Meeting" - body: - description: "The email body" - type: "string" - example: "Hello, I would like to schedule a meeting with you." - Interaction: - required: - - type - type: "object" - discriminator: - propertyName: "type" - mapping: - chat-message: "#/components/schemas/ChatMessage" - email: "#/components/schemas/Email" - properties: - type: - description: "The type of interaction" - enum: - - "call" - - "email" - - "meeting" - - "chat-message" - example: "meeting" - type: "string" - oneOf: - - $ref: "#/components/schemas/ChatMessage" - - $ref: "#/components/schemas/Email" \ No newline at end of file diff --git a/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts b/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts index d994fd35e98..8a1b41ec04c 100644 --- a/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts +++ b/samples/client/others/typescript/builds/with-unique-items/models/ObjectSerializer.ts @@ -97,8 +97,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } diff --git a/samples/client/others/typescript/builds/with-unique-items/models/Response.ts b/samples/client/others/typescript/builds/with-unique-items/models/Response.ts index 6a53fbd9f9d..9ba6412f244 100644 --- a/samples/client/others/typescript/builds/with-unique-items/models/Response.ts +++ b/samples/client/others/typescript/builds/with-unique-items/models/Response.ts @@ -18,6 +18,8 @@ export class Response { 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": "nonUniqueArray", @@ -39,4 +41,3 @@ export class Response { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/ApiResponse.ts index f4b2d010fb7..3dd68507b21 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Category.ts index 5d63fc87a99..e025011174d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts index 97a82f53c20..ec528248327 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 4d80550bb2a..b8d4a26c7d4 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 ecaefffea4f..ddb68aa82a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/Tag.ts index 8c4f6967b9a..7a7a36ba59a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/browser/models/User.ts index 68528ad3c9e..4dbe18f7fed 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Cat.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Cat.ts index 2790b653b55..7812787becb 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Cat.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/Cat.ts @@ -18,6 +18,8 @@ export class Cat { 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": "hunts", @@ -39,4 +41,3 @@ export class Cat { public constructor() { } } - 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 4d83c9db754..5a3e5f0fa48 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 @@ -18,6 +18,8 @@ export class Dog { 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": "bark", @@ -40,7 +42,6 @@ export class Dog { } } - export enum DogBreedEnum { Dingo = 'Dingo', Husky = 'Husky', diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/FilePostRequest.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/FilePostRequest.ts index ddd7a052d56..5a51233579e 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/FilePostRequest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/FilePostRequest.ts @@ -17,6 +17,8 @@ export class FilePostRequest { 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": "file", @@ -32,4 +34,3 @@ export class FilePostRequest { public constructor() { } } - 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 c98b183b5b6..dff7067ea8d 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 @@ -12,7 +12,7 @@ import { FilePostRequest } from '../models/FilePostRequest'; import { PetByAge } from '../models/PetByAge'; import { PetByType, PetByTypePetTypeEnum } from '../models/PetByType'; import { PetsFilteredPatchRequest , PetsFilteredPatchRequestPetTypeEnum } from '../models/PetsFilteredPatchRequest'; -import { PetsPatchRequest , PetsPatchRequestBreedEnum } from '../models/PetsPatchRequest'; +import { PetsPatchRequestClass } from '../models/PetsPatchRequest'; /* tslint:disable:no-unused-variable */ let primitives = [ @@ -40,7 +40,7 @@ let typeMap: {[index: string]: any} = { "PetByAge": PetByAge, "PetByType": PetByType, "PetsFilteredPatchRequest": PetsFilteredPatchRequest, - "PetsPatchRequest": PetsPatchRequest, + "PetsPatchRequest": PetsPatchRequestClass, } type MimeTypeDescriptor = { @@ -119,8 +119,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByAge.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByAge.ts index 6c7e3c20f0f..5ddcb270eb2 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByAge.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/PetByAge.ts @@ -18,6 +18,8 @@ export class PetByAge { 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": "age", @@ -39,4 +41,3 @@ export class PetByAge { public constructor() { } } - 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 4306e8ead93..60d1fd207e2 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 @@ -18,6 +18,8 @@ export class PetByType { 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": "petType", @@ -40,7 +42,6 @@ export class PetByType { } } - 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 4eaec36a60c..067783a5332 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 @@ -22,6 +22,8 @@ export class PetsFilteredPatchRequest { 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": "age", @@ -56,7 +58,6 @@ export class PetsFilteredPatchRequest { } } - 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 7c1009e3d51..29d1f50c615 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 @@ -14,54 +14,20 @@ import { Cat } from '../models/Cat'; import { Dog } from '../models/Dog'; import { HttpFile } from '../http/http'; -export class PetsPatchRequest { - 'hunts'?: boolean; - 'age'?: number; - 'bark'?: boolean; - 'breed'?: PetsPatchRequestBreedEnum; +/** + * @type PetsPatchRequest + * Type + * @export + */ +export type PetsPatchRequest = Cat | Dog; +/** +* @type PetsPatchRequestClass +* @export +*/ +export class PetsPatchRequestClass { static readonly discriminator: string | undefined = "petType"; - static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ - { - "name": "hunts", - "baseName": "hunts", - "type": "boolean", - "format": "" - }, - { - "name": "age", - "baseName": "age", - "type": "number", - "format": "" - }, - { - "name": "bark", - "baseName": "bark", - "type": "boolean", - "format": "" - }, - { - "name": "breed", - "baseName": "breed", - "type": "PetsPatchRequestBreedEnum", - "format": "" - } ]; - - static getAttributeTypeMap() { - return PetsPatchRequest.attributeTypeMap; - } - - public constructor() { - this.petType = "PetsPatchRequest"; - } -} - - -export enum PetsPatchRequestBreedEnum { - Dingo = 'Dingo', - Husky = 'Husky', - Retriever = 'Retriever', - Shepherd = 'Shepherd' + static readonly mapping: {[index: string]: string} | undefined = undefined; } diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/ApiResponse.ts index f4b2d010fb7..3dd68507b21 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Category.ts index 5d63fc87a99..e025011174d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts index 97a82f53c20..ec528248327 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 4d80550bb2a..b8d4a26c7d4 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 ecaefffea4f..ddb68aa82a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/Tag.ts index 8c4f6967b9a..7a7a36ba59a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/default/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/default/models/User.ts index 68528ad3c9e..4dbe18f7fed 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/ApiResponse.ts index b5cfa4948a0..55426844f46 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Category.ts index 9c1bdd23614..69f46a847ef 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts index bea859c615b..32490364bb7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 63e6b8fe3f1..ca36df140b3 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 1404661b6de..7cbaa216062 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/Tag.ts index dc2c98212c3..e443aa10230 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/deno/models/User.ts index 76c6a9ae869..c728f6fd763 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ApiResponse.ts index b5cfa4948a0..55426844f46 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Category.ts index 9c1bdd23614..69f46a847ef 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts index bea859c615b..32490364bb7 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Order.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Order.ts index 63e6b8fe3f1..ca36df140b3 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Pet.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Pet.ts index 1404661b6de..7cbaa216062 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Tag.ts index dc2c98212c3..e443aa10230 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/User.ts index 76c6a9ae869..c728f6fd763 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/.gitignore b/samples/openapi3/client/petstore/typescript/builds/enum/.gitignore deleted file mode 100644 index 1521c8b7652..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator-ignore b/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a3..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# Use this file to prevent files from being overwritten by the generator. -# The patterns follow closely to .gitignore or .dockerignore. - -# As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: -#ApiClient.cs - -# You can match any string of characters against a directory, file or extension with a single asterisk (*): -#foo/*/qux -# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux - -# You can recursively match patterns against a directory, file or extension with a double asterisk (**): -#foo/**/qux -# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux - -# You can also negate patterns with an exclamation (!). -# For example, you can ignore all files in a docs folder with the file extension .md: -#docs/*.md -# Then explicitly reverse the ignore rule for a single file: -#!docs/README.md diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/FILES b/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/FILES deleted file mode 100644 index 6d77359bddc..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/FILES +++ /dev/null @@ -1,23 +0,0 @@ -.gitignore -DefaultApi.md -apis/DefaultApi.ts -apis/baseapi.ts -apis/exception.ts -auth/auth.ts -configuration.ts -git_push.sh -http/http.ts -http/isomorphic-fetch.ts -index.ts -middleware.ts -models/ChatMessage.ts -models/Email.ts -models/Interaction.ts -models/ObjectSerializer.ts -models/all.ts -rxjsStub.ts -servers.ts -types/ObjectParamAPI.ts -types/ObservableAPI.ts -types/PromiseAPI.ts -util.ts diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/VERSION b/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/VERSION deleted file mode 100644 index 17f2442ff3b..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -7.9.0-SNAPSHOT diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/DefaultApi.md b/samples/openapi3/client/petstore/typescript/builds/enum/DefaultApi.md deleted file mode 100644 index 496d8a07d24..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/DefaultApi.md +++ /dev/null @@ -1,64 +0,0 @@ -# petstore.DefaultApi - -All URIs are relative to *http://localhost* - -Method | HTTP request | Description -------------- | ------------- | ------------- -[**interactionsGet**](DefaultApi.md#interactionsGet) | **GET** /interactions | Returns all interactions. - - -# **interactionsGet** -> Interaction interactionsGet() - -Optional extended description in Markdown. - -### Example - - -```typescript -import { petstore } from 'ts-petstore-client'; -import * as fs from 'fs'; - -const configuration = petstore.createConfiguration(); -const apiInstance = new petstore.DefaultApi(configuration); - -let body:petstore.DefaultApiInteractionsGetRequest = { - // string (optional) - parameterTypeMapping: "parameter_type_mapping_example", -}; - -apiInstance.interactionsGet(body).then((data:any) => { - console.log('API called successfully. Returned data: ' + data); -}).catch((error:any) => console.error(error)); -``` - - -### Parameters - -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **parameterTypeMapping** | [**string**] | | (optional) defaults to undefined - - -### Return type - -**Interaction** - -### Authorization - -No authorization required - -### HTTP request headers - - - **Content-Type**: Not defined - - **Accept**: application/json - - -### HTTP response details -| Status code | Description | Response headers | -|-------------|-------------|------------------| -**200** | OK | - | - -[[Back to top]](#) [[Back to API list]](README.md#documentation-for-api-endpoints) [[Back to Model list]](README.md#documentation-for-models) [[Back to README]](README.md) - - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/apis/DefaultApi.ts b/samples/openapi3/client/petstore/typescript/builds/enum/apis/DefaultApi.ts deleted file mode 100644 index 41284612bd1..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/apis/DefaultApi.ts +++ /dev/null @@ -1,82 +0,0 @@ -// TODO: better import syntax? -import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi.ts'; -import {Configuration} from '../configuration.ts'; -import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http.ts'; -import {ObjectSerializer} from '../models/ObjectSerializer.ts'; -import {ApiException} from './exception.ts'; -import {canConsumeForm, isCodeInRange} from '../util.ts'; -import {SecurityAuthentication} from '../auth/auth.ts'; - - -import { Interaction } from '../models/Interaction.ts'; - -/** - * no description - */ -export class DefaultApiRequestFactory extends BaseAPIRequestFactory { - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param parameterTypeMapping - */ - public async interactionsGet(parameterTypeMapping?: string, _options?: Configuration): Promise { - let _config = _options || this.configuration; - - - // Path Params - const localVarPath = '/interactions'; - - // Make Request Context - const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); - requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") - - // Query Params - if (parameterTypeMapping !== undefined) { - requestContext.setQueryParam("parameter_type_mapping", ObjectSerializer.serialize(parameterTypeMapping, "string", "special")); - } - - - - const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default - if (defaultAuth?.applySecurityAuthentication) { - await defaultAuth?.applySecurityAuthentication(requestContext); - } - - return requestContext; - } - -} - -export class DefaultApiResponseProcessor { - - /** - * Unwraps the actual response sent by the server from the response context and deserializes the response content - * to the expected objects - * - * @params response Response returned by the server for a request to interactionsGet - * @throws ApiException if the response code was not in [200, 299] - */ - public async interactionsGetWithHttpInfo(response: ResponseContext): Promise> { - const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); - if (isCodeInRange("200", response.httpStatusCode)) { - const body: Interaction = ObjectSerializer.deserialize( - ObjectSerializer.parse(await response.body.text(), contentType), - "Interaction", "" - ) as Interaction; - return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); - } - - // Work around for missing responses in specification, e.g. for petstore.yaml - if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { - const body: Interaction = ObjectSerializer.deserialize( - ObjectSerializer.parse(await response.body.text(), contentType), - "Interaction", "" - ) as Interaction; - return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); - } - - throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); - } - -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/apis/baseapi.ts b/samples/openapi3/client/petstore/typescript/builds/enum/apis/baseapi.ts deleted file mode 100644 index 46ed74bb556..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/apis/baseapi.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Configuration } from '../configuration.ts' - -/** - * - * @export - */ -export const COLLECTION_FORMATS = { - csv: ",", - ssv: " ", - tsv: "\t", - pipes: "|", -}; - - -/** - * - * @export - * @class BaseAPI - */ -export class BaseAPIRequestFactory { - - constructor(protected configuration: Configuration) { - } -}; - -/** - * - * @export - * @class RequiredError - * @extends {Error} - */ -export class RequiredError extends Error { - name: "RequiredError" = "RequiredError"; - constructor(public api: string, public method: string, public field: string) { - super("Required parameter " + field + " was null or undefined when calling " + api + "." + method + "."); - } -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/apis/exception.ts b/samples/openapi3/client/petstore/typescript/builds/enum/apis/exception.ts deleted file mode 100644 index 9365d33a8f7..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/apis/exception.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Represents an error caused by an api call i.e. it has attributes for a HTTP status code - * and the returned body object. - * - * Example - * API returns a ErrorMessageObject whenever HTTP status code is not in [200, 299] - * => ApiException(404, someErrorMessageObject) - * - */ -export class ApiException extends Error { - public constructor(public code: number, message: string, public body: T, public headers: { [key: string]: string; }) { - super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " + - JSON.stringify(headers)) - } -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/auth/auth.ts b/samples/openapi3/client/petstore/typescript/builds/enum/auth/auth.ts deleted file mode 100644 index 21508e95104..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/auth/auth.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { RequestContext } from "../http/http.ts"; - -/** - * Interface authentication schemes. - */ -export interface SecurityAuthentication { - /* - * @return returns the name of the security authentication as specified in OAI - */ - getName(): string; - - /** - * Applies the authentication scheme to the request context - * - * @params context the request context which should use this authentication scheme - */ - applySecurityAuthentication(context: RequestContext): void | Promise; -} - -export interface TokenProvider { - getToken(): Promise | string; -} - - -export type AuthMethods = { - "default"?: SecurityAuthentication, -} - -export type ApiKeyConfiguration = string; -export type HttpBasicConfiguration = { "username": string, "password": string }; -export type HttpBearerConfiguration = { tokenProvider: TokenProvider }; -export type OAuth2Configuration = { accessToken: string }; - -export type AuthMethodsConfiguration = { - "default"?: SecurityAuthentication, -} - -/** - * Creates the authentication methods from a swagger description. - * - */ -export function configureAuthMethods(config: AuthMethodsConfiguration | undefined): AuthMethods { - let authMethods: AuthMethods = {} - - if (!config) { - return authMethods; - } - authMethods["default"] = config["default"] - - return authMethods; -} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/configuration.ts b/samples/openapi3/client/petstore/typescript/builds/enum/configuration.ts deleted file mode 100644 index 0a170f0d507..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/configuration.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { HttpLibrary } from "./http/http.ts"; -import { Middleware, PromiseMiddleware, PromiseMiddlewareWrapper } from "./middleware.ts"; -import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch.ts"; -import { BaseServerConfiguration, server1 } from "./servers.ts"; -import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth.ts"; - -export interface Configuration { - readonly baseServer: BaseServerConfiguration; - readonly httpApi: HttpLibrary; - readonly middleware: Middleware[]; - readonly authMethods: AuthMethods; -} - - -/** - * Interface with which a configuration object can be configured. - */ -export interface ConfigurationParameters { - /** - * Default server to use - a list of available servers (according to the - * OpenAPI yaml definition) is included in the `servers` const in `./servers`. You can also - * create your own server with the `ServerConfiguration` class from the same - * file. - */ - baseServer?: BaseServerConfiguration; - /** - * HTTP library to use e.g. IsomorphicFetch. This can usually be skipped as - * all generators come with a default library. - * If available, additional libraries can be imported from `./http/*` - */ - httpApi?: HttpLibrary; - - /** - * The middlewares which will be applied to requests and responses. You can - * add any number of middleware components to modify requests before they - * are sent or before they are deserialized by implementing the `Middleware` - * interface defined in `./middleware` - */ - middleware?: Middleware[]; - /** - * Configures middleware functions that return promises instead of - * Observables (which are used by `middleware`). Otherwise allows for the - * same functionality as `middleware`, i.e., modifying requests before they - * are sent and before they are deserialized. - */ - promiseMiddleware?: PromiseMiddleware[]; - /** - * Configuration for the available authentication methods (e.g., api keys) - * according to the OpenAPI yaml definition. For the definition, please refer to - * `./auth/auth` - */ - authMethods?: AuthMethodsConfiguration -} - -/** - * Provide your `ConfigurationParameters` to this function to get a `Configuration` - * object that can be used to configure your APIs (in the constructor or - * for each request individually). - * - * If a property is not included in conf, a default is used: - * - baseServer: server1 - * - httpApi: IsomorphicFetchHttpLibrary - * - middleware: [] - * - promiseMiddleware: [] - * - authMethods: {} - * - * @param conf partial configuration - */ -export function createConfiguration(conf: ConfigurationParameters = {}): Configuration { - const configuration: Configuration = { - baseServer: conf.baseServer !== undefined ? conf.baseServer : server1, - httpApi: conf.httpApi || new DefaultHttpLibrary(), - middleware: conf.middleware || [], - authMethods: configureAuthMethods(conf.authMethods) - }; - if (conf.promiseMiddleware) { - conf.promiseMiddleware.forEach( - m => configuration.middleware.push(new PromiseMiddlewareWrapper(m)) - ); - } - return configuration; -} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/git_push.sh b/samples/openapi3/client/petstore/typescript/builds/enum/git_push.sh deleted file mode 100644 index b253029754e..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/git_push.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 - -if [ "$git_user_id" = "" ]; then - git_user_id="GIT_USER_ID" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="GIT_REPO_ID" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="Minor update" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=$(git remote) -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@github.com/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/enum/http/http.ts deleted file mode 100644 index 29fc7c39f61..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/http/http.ts +++ /dev/null @@ -1,238 +0,0 @@ -import { Observable, from } from '../rxjsStub.ts'; - - -/** - * Represents an HTTP method. - */ -export enum HttpMethod { - GET = "GET", - HEAD = "HEAD", - POST = "POST", - PUT = "PUT", - DELETE = "DELETE", - CONNECT = "CONNECT", - OPTIONS = "OPTIONS", - TRACE = "TRACE", - PATCH = "PATCH" -} - -/** - * Represents an HTTP file which will be transferred from or to a server. - */ -export type HttpFile = Blob & { readonly name: string }; - -export class HttpException extends Error { - public constructor(msg: string) { - super(msg); - } -} - -/** - * Represents the body of an outgoing HTTP request. - */ -export type RequestBody = undefined | string | FormData | URLSearchParams; - -function ensureAbsoluteUrl(url: string) { - if (url.startsWith("http://") || url.startsWith("https://")) { - return url; - } - return window.location.origin + url; -} - -/** - * Represents an HTTP request context - */ -export class RequestContext { - private headers: { [key: string]: string } = {}; - private body: RequestBody = undefined; - private url: URL; - - /** - * Creates the request context using a http method and request resource url - * - * @param url url of the requested resource - * @param httpMethod http method - */ - public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URL(ensureAbsoluteUrl(url)); - } - - /* - * Returns the url set in the constructor including the query string - * - */ - public getUrl(): string { - return this.url.toString().endsWith("/") ? - this.url.toString().slice(0, -1) - : this.url.toString(); - } - - /** - * Replaces the url set in the constructor with this url. - * - */ - public setUrl(url: string) { - this.url = new URL(ensureAbsoluteUrl(url)); - } - - /** - * Sets the body of the http request either as a string or FormData - * - * Note that setting a body on a HTTP GET, HEAD, DELETE, CONNECT or TRACE - * request is discouraged. - * https://httpwg.org/http-core/draft-ietf-httpbis-semantics-latest.html#rfc.section.7.3.1 - * - * @param body the body of the request - */ - public setBody(body: RequestBody) { - this.body = body; - } - - public getHttpMethod(): HttpMethod { - return this.httpMethod; - } - - public getHeaders(): { [key: string]: string } { - return this.headers; - } - - public getBody(): RequestBody { - return this.body; - } - - public setQueryParam(name: string, value: string) { - this.url.searchParams.set(name, value); - } - - /** - * Sets a cookie with the name and value. NO check for duplicate cookies is performed - * - */ - public addCookie(name: string, value: string): void { - if (!this.headers["Cookie"]) { - this.headers["Cookie"] = ""; - } - this.headers["Cookie"] += name + "=" + value + "; "; - } - - public setHeaderParam(key: string, value: string): void { - this.headers[key] = value; - } -} - -export interface ResponseBody { - text(): Promise; - binary(): Promise; -} - -/** - * Helper class to generate a `ResponseBody` from binary data - */ -export class SelfDecodingBody implements ResponseBody { - constructor(private dataSource: Promise) {} - - binary(): Promise { - return this.dataSource; - } - - async text(): Promise { - const data: Blob = await this.dataSource; - return data.text(); - } -} - -export class ResponseContext { - public constructor( - public httpStatusCode: number, - public headers: { [key: string]: string }, - public body: ResponseBody - ) {} - - /** - * Parse header value in the form `value; param1="value1"` - * - * E.g. for Content-Type or Content-Disposition - * Parameter names are converted to lower case - * The first parameter is returned with the key `""` - */ - public getParsedHeader(headerName: string): { [parameter: string]: string } { - const result: { [parameter: string]: string } = {}; - if (!this.headers[headerName]) { - return result; - } - - const parameters = this.headers[headerName].split(";"); - for (const parameter of parameters) { - let [key, value] = parameter.split("=", 2); - key = key.toLowerCase().trim(); - if (value === undefined) { - result[""] = key; - } else { - value = value.trim(); - if (value.startsWith('"') && value.endsWith('"')) { - value = value.substring(1, value.length - 1); - } - result[key] = value; - } - } - return result; - } - - public async getBodyAsFile(): Promise { - const data = await this.body.binary(); - const fileName = this.getParsedHeader("content-disposition")["filename"] || ""; - const contentType = this.headers["content-type"] || ""; - try { - return new File([data], fileName, { type: contentType }); - } catch (error) { - /** Fallback for when the File constructor is not available */ - return Object.assign(data, { - name: fileName, - type: contentType - }); - } - } - - /** - * Use a heuristic to get a body of unknown data structure. - * Return as string if possible, otherwise as binary. - */ - public getBodyAsAny(): Promise { - try { - return this.body.text(); - } catch {} - - try { - return this.body.binary(); - } catch {} - - return Promise.resolve(undefined); - } -} - -export interface HttpLibrary { - send(request: RequestContext): Observable; -} - -export interface PromiseHttpLibrary { - send(request: RequestContext): Promise; -} - -export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLibrary { - return { - send(request: RequestContext): Observable { - return from(promiseHttpLibrary.send(request)); - } - } -} - -export class HttpInfo extends ResponseContext { - public constructor( - public httpStatusCode: number, - public headers: { [key: string]: string }, - public body: ResponseBody, - public data: T, - ) { - super(httpStatusCode, headers, body); - } -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/http/isomorphic-fetch.ts b/samples/openapi3/client/petstore/typescript/builds/enum/http/isomorphic-fetch.ts deleted file mode 100644 index a7521351e06..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/http/isomorphic-fetch.ts +++ /dev/null @@ -1,30 +0,0 @@ -import {HttpLibrary, RequestContext, ResponseContext} from './http.ts'; -import { from, Observable } from '../rxjsStub.ts'; - -export class IsomorphicFetchHttpLibrary implements HttpLibrary { - - public send(request: RequestContext): Observable { - let method = request.getHttpMethod().toString(); - let body = request.getBody(); - - const resultPromise = fetch(request.getUrl(), { - method: method, - body: body as any, - headers: request.getHeaders(), - }).then((resp: any) => { - const headers: { [name: string]: string } = {}; - resp.headers.forEach((value: string, name: string) => { - headers[name] = value; - }); - - const body = { - text: () => resp.text(), - binary: () => resp.blob() - }; - return new ResponseContext(resp.status, headers, body); - }); - - return from>(resultPromise); - - } -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/index.ts b/samples/openapi3/client/petstore/typescript/builds/enum/index.ts deleted file mode 100644 index 9ec077f07fb..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -export * from "./http/http.ts"; -export * from "./auth/auth.ts"; -export * from "./models/all.ts"; -export { createConfiguration } from "./configuration.ts" -export type { Configuration } from "./configuration.ts" -export * from "./apis/exception.ts"; -export * from "./servers.ts"; -export { RequiredError } from "./apis/baseapi.ts"; - -export type { PromiseMiddleware as Middleware } from './middleware.ts'; -export { PromiseDefaultApi as DefaultApi } from './types/PromiseAPI.ts'; - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/middleware.ts b/samples/openapi3/client/petstore/typescript/builds/enum/middleware.ts deleted file mode 100644 index ae36e6c3d7d..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/middleware.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {RequestContext, ResponseContext} from './http/http.ts'; -import { Observable, from } from './rxjsStub.ts'; - -/** - * Defines the contract for a middleware intercepting requests before - * they are sent (but after the RequestContext was created) - * and before the ResponseContext is unwrapped. - * - */ -export interface Middleware { - /** - * Modifies the request before the request is sent. - * - * @param context RequestContext of a request which is about to be sent to the server - * @returns an observable of the updated request context - * - */ - pre(context: RequestContext): Observable; - /** - * Modifies the returned response before it is deserialized. - * - * @param context ResponseContext of a sent request - * @returns an observable of the modified response context - */ - post(context: ResponseContext): Observable; -} - -export class PromiseMiddlewareWrapper implements Middleware { - - public constructor(private middleware: PromiseMiddleware) { - - } - - pre(context: RequestContext): Observable { - return from(this.middleware.pre(context)); - } - - post(context: ResponseContext): Observable { - return from(this.middleware.post(context)); - } - -} - -/** - * Defines the contract for a middleware intercepting requests before - * they are sent (but after the RequestContext was created) - * and before the ResponseContext is unwrapped. - * - */ -export interface PromiseMiddleware { - /** - * Modifies the request before the request is sent. - * - * @param context RequestContext of a request which is about to be sent to the server - * @returns an observable of the updated request context - * - */ - pre(context: RequestContext): Promise; - /** - * Modifies the returned response before it is deserialized. - * - * @param context ResponseContext of a sent request - * @returns an observable of the modified response context - */ - post(context: ResponseContext): Promise; -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/models/ChatMessage.ts b/samples/openapi3/client/petstore/typescript/builds/enum/models/ChatMessage.ts deleted file mode 100644 index 64fcef6b62a..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/models/ChatMessage.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Sample API to test enum mapping - * API description in Markdown. - * - * 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 { HttpFile } from '../http/http.ts'; - -export class ChatMessage { - /** - * The type of interaction - */ - 'type'?: ChatMessageTypeEnum; - /** - * The message content - */ - 'message'?: string; - - static readonly discriminator: string | undefined = undefined; - - static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ - { - "name": "type", - "baseName": "type", - "type": "ChatMessageTypeEnum", - "format": "" - }, - { - "name": "message", - "baseName": "message", - "type": "string", - "format": "" - } ]; - - static getAttributeTypeMap() { - return ChatMessage.attributeTypeMap; - } - - public constructor() { - } -} - - -export enum ChatMessageTypeEnum { - ChatMessage = 'chat-message' -} - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/models/Email.ts b/samples/openapi3/client/petstore/typescript/builds/enum/models/Email.ts deleted file mode 100644 index d1fa32910bd..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/models/Email.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Sample API to test enum mapping - * API description in Markdown. - * - * 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 { HttpFile } from '../http/http.ts'; - -export class Email { - /** - * The type of interaction - */ - 'type'?: EmailTypeEnum; - /** - * The email subject - */ - 'subject'?: string; - /** - * The email body - */ - 'body'?: string; - - static readonly discriminator: string | undefined = undefined; - - static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ - { - "name": "type", - "baseName": "type", - "type": "EmailTypeEnum", - "format": "" - }, - { - "name": "subject", - "baseName": "subject", - "type": "string", - "format": "" - }, - { - "name": "body", - "baseName": "body", - "type": "string", - "format": "" - } ]; - - static getAttributeTypeMap() { - return Email.attributeTypeMap; - } - - public constructor() { - } -} - - -export enum EmailTypeEnum { - Email = 'email' -} - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/models/Interaction.ts b/samples/openapi3/client/petstore/typescript/builds/enum/models/Interaction.ts deleted file mode 100644 index 113af3072d6..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/models/Interaction.ts +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Sample API to test enum mapping - * API description in Markdown. - * - * 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 { ChatMessage } from '../models/ChatMessage.ts'; -import { Email } from '../models/Email.ts'; -import { HttpFile } from '../http/http.ts'; - -export class Interaction { - /** - * The type of interaction - */ - 'type': InteractionTypeEnum; - /** - * The message content - */ - 'message'?: string; - /** - * The email subject - */ - 'subject'?: string; - /** - * The email body - */ - 'body'?: string; - - static readonly discriminator: string | undefined = "type"; - - static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ - { - "name": "type", - "baseName": "type", - "type": "InteractionTypeEnum", - "format": "" - }, - { - "name": "message", - "baseName": "message", - "type": "string", - "format": "" - }, - { - "name": "subject", - "baseName": "subject", - "type": "string", - "format": "" - }, - { - "name": "body", - "baseName": "body", - "type": "string", - "format": "" - } ]; - - static getAttributeTypeMap() { - return Interaction.attributeTypeMap; - } - - public constructor() { - } -} - - -export enum InteractionTypeEnum { - Call = 'call', - Email = 'email', - Meeting = 'meeting', - ChatMessage = 'chat-message' -} - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/enum/models/ObjectSerializer.ts deleted file mode 100644 index 7573d71759e..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/models/ObjectSerializer.ts +++ /dev/null @@ -1,275 +0,0 @@ -export * from '../models/ChatMessage.ts'; -export * from '../models/Email.ts'; -export * from '../models/Interaction.ts'; - -import { ChatMessage, ChatMessageTypeEnum } from '../models/ChatMessage.ts'; -import { Email, EmailTypeEnum } from '../models/Email.ts'; -import { Interaction, InteractionTypeEnum } from '../models/Interaction.ts'; - -/* tslint:disable:no-unused-variable */ -let primitives = [ - "string", - "boolean", - "double", - "integer", - "long", - "float", - "number", - "any" - ]; - -let enumsMap: Set = new Set([ - "ChatMessageTypeEnum", - "EmailTypeEnum", - "InteractionTypeEnum", -]); - -let typeMap: {[index: string]: any} = { - "ChatMessage": ChatMessage, - "Email": Email, - "Interaction": Interaction, -} - -type MimeTypeDescriptor = { - type: string; - subtype: string; - subtypeTokens: string[]; -}; - -/** - * Every mime-type consists of a type, subtype, and optional parameters. - * The subtype can be composite, including information about the content format. - * For example: `application/json-patch+json`, `application/merge-patch+json`. - * - * This helper transforms a string mime-type into an internal representation. - * This simplifies the implementation of predicates that in turn define common rules for parsing or stringifying - * the payload. - */ -const parseMimeType = (mimeType: string): MimeTypeDescriptor => { - const [type, subtype] = mimeType.split('/'); - return { - type, - subtype, - subtypeTokens: subtype.split('+'), - }; -}; - -type MimeTypePredicate = (mimeType: string) => boolean; - -// This factory creates a predicate function that checks a string mime-type against defined rules. -const mimeTypePredicateFactory = (predicate: (descriptor: MimeTypeDescriptor) => boolean): MimeTypePredicate => (mimeType) => predicate(parseMimeType(mimeType)); - -// Use this factory when you need to define a simple predicate based only on type and, if applicable, subtype. -const mimeTypeSimplePredicateFactory = (type: string, subtype?: string): MimeTypePredicate => mimeTypePredicateFactory((descriptor) => { - if (descriptor.type !== type) return false; - if (subtype != null && descriptor.subtype !== subtype) return false; - return true; -}); - -// Creating a set of named predicates that will help us determine how to handle different mime-types -const isTextLikeMimeType = mimeTypeSimplePredicateFactory('text'); -const isJsonMimeType = mimeTypeSimplePredicateFactory('application', 'json'); -const isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === 'application' && descriptor.subtypeTokens.some((item) => item === 'json')); -const isOctetStreamMimeType = mimeTypeSimplePredicateFactory('application', 'octet-stream'); -const isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory('application', 'x-www-form-urlencoded'); - -// Defining a list of mime-types in the order of prioritization for handling. -const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [ - isJsonMimeType, - isJsonLikeMimeType, - isTextLikeMimeType, - isOctetStreamMimeType, - isFormUrlencodedMimeType, -]; - -export class ObjectSerializer { - public static findCorrectType(data: any, expectedType: string) { - if (data == undefined) { - return expectedType; - } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { - return expectedType; - } else if (expectedType === "Date") { - return expectedType; - } else { - if (enumsMap.has(expectedType)) { - return expectedType; - } - - if (!typeMap[expectedType]) { - return expectedType; // w/e we don't know the type - } - - // Check the discriminator - let discriminatorProperty = typeMap[expectedType].discriminator; - if (discriminatorProperty == null) { - return expectedType; // the type does not have a discriminator. use it. - } else { - if (data[discriminatorProperty]) { - var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator - } else { - return expectedType; // discriminator did not map to a type - } - } else { - return expectedType; // discriminator was not present (or an empty string) - } - } - } - } - - public static serialize(data: any, type: string, format: string) { - if (data == undefined) { - return data; - } else if (primitives.indexOf(type.toLowerCase()) !== -1) { - return data; - } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 - let subType: string = type.replace("Array<", ""); // Array => Type> - subType = subType.substring(0, subType.length - 1); // Type> => Type - let transformedData: any[] = []; - for (let date of data) { - transformedData.push(ObjectSerializer.serialize(date, subType, format)); - } - return transformedData; - } else if (type === "Date") { - if (format == "date") { - let month = data.getMonth()+1 - month = month < 10 ? "0" + month.toString() : month.toString() - let day = data.getDate(); - day = day < 10 ? "0" + day.toString() : day.toString(); - - return data.getFullYear() + "-" + month + "-" + day; - } else { - return data.toISOString(); - } - } else { - if (enumsMap.has(type)) { - return data; - } - if (!typeMap[type]) { // in case we dont know the type - return data; - } - - // Get the actual type of this object - type = this.findCorrectType(data, type); - - // get the map for the correct type. - let attributeTypes = typeMap[type].getAttributeTypeMap(); - let instance: {[index: string]: any} = {}; - for (let attributeType of attributeTypes) { - instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format); - } - return instance; - } - } - - public static deserialize(data: any, type: string, format: string) { - // polymorphism may change the actual type. - type = ObjectSerializer.findCorrectType(data, type); - if (data == undefined) { - return data; - } else if (primitives.indexOf(type.toLowerCase()) !== -1) { - return data; - } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 - let subType: string = type.replace("Array<", ""); // Array => Type> - subType = subType.substring(0, subType.length - 1); // Type> => Type - let transformedData: any[] = []; - for (let date of data) { - transformedData.push(ObjectSerializer.deserialize(date, subType, format)); - } - return transformedData; - } else if (type === "Date") { - return new Date(data); - } else { - if (enumsMap.has(type)) {// is Enum - return data; - } - - if (!typeMap[type]) { // dont know the type - return data; - } - let instance = new typeMap[type](); - let attributeTypes = typeMap[type].getAttributeTypeMap(); - for (let attributeType of attributeTypes) { - let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format); - if (value !== undefined) { - instance[attributeType.name] = value; - } - } - return instance; - } - } - - - /** - * Normalize media type - * - * We currently do not handle any media types attributes, i.e. anything - * after a semicolon. All content is assumed to be UTF-8 compatible. - */ - public static normalizeMediaType(mediaType: string | undefined): string | undefined { - if (mediaType === undefined) { - return undefined; - } - return mediaType.split(";")[0].trim().toLowerCase(); - } - - /** - * From a list of possible media types, choose the one we can handle best. - * - * The order of the given media types does not have any impact on the choice - * made. - */ - public static getPreferredMediaType(mediaTypes: Array): string { - /** According to OAS 3 we should default to json */ - if (mediaTypes.length === 0) { - return "application/json"; - } - - const normalMediaTypes = mediaTypes.map(this.normalizeMediaType); - - for (const predicate of supportedMimeTypePredicatesWithPriority) { - for (const mediaType of normalMediaTypes) { - if (mediaType != null && predicate(mediaType)) { - return mediaType; - } - } - } - - throw new Error("None of the given media types are supported: " + mediaTypes.join(", ")); - } - - /** - * Convert data to a string according the given media type - */ - public static stringify(data: any, mediaType: string): string { - if (isTextLikeMimeType(mediaType)) { - return String(data); - } - - if (isJsonLikeMimeType(mediaType)) { - return JSON.stringify(data); - } - - throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify."); - } - - /** - * Parse data from a string according to the given media type - */ - public static parse(rawData: string, mediaType: string | undefined) { - if (mediaType === undefined) { - throw new Error("Cannot parse content. No Content-Type defined."); - } - - if (isTextLikeMimeType(mediaType)) { - return rawData; - } - - if (isJsonLikeMimeType(mediaType)) { - return JSON.parse(rawData); - } - - throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse."); - } -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/models/all.ts b/samples/openapi3/client/petstore/typescript/builds/enum/models/all.ts deleted file mode 100644 index c7d7a4a494d..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/models/all.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from '../models/ChatMessage.ts' -export * from '../models/Email.ts' -export * from '../models/Interaction.ts' diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/rxjsStub.ts b/samples/openapi3/client/petstore/typescript/builds/enum/rxjsStub.ts deleted file mode 100644 index 4c73715a248..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/rxjsStub.ts +++ /dev/null @@ -1,27 +0,0 @@ -export class Observable { - constructor(private promise: Promise) {} - - toPromise() { - return this.promise; - } - - pipe(callback: (value: T) => S | Promise): Observable { - return new Observable(this.promise.then(callback)); - } -} - -export function from(promise: Promise) { - return new Observable(promise); -} - -export function of(value: T) { - return new Observable(Promise.resolve(value)); -} - -export function mergeMap(callback: (value: T) => Observable) { - return (value: T) => callback(value).toPromise(); -} - -export function map(callback: any) { - return callback; -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/servers.ts b/samples/openapi3/client/petstore/typescript/builds/enum/servers.ts deleted file mode 100644 index f47dbd79412..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/servers.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { RequestContext, HttpMethod } from "./http/http.ts"; - -export interface BaseServerConfiguration { - makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext; -} - -/** - * - * Represents the configuration of a server including its - * url template and variable configuration based on the url. - * - */ -export class ServerConfiguration implements BaseServerConfiguration { - public constructor(private url: string, private variableConfiguration: T) {} - - /** - * Sets the value of the variables of this server. Variables are included in - * the `url` of this ServerConfiguration in the form `{variableName}` - * - * @param variableConfiguration a partial variable configuration for the - * variables contained in the url - */ - public setVariables(variableConfiguration: Partial) { - Object.assign(this.variableConfiguration, variableConfiguration); - } - - public getConfiguration(): T { - return this.variableConfiguration - } - - private getUrl() { - let replacedUrl = this.url; - for (const key in this.variableConfiguration) { - var re = new RegExp("{" + key + "}","g"); - replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); - } - return replacedUrl - } - - /** - * Creates a new request context for this server using the url with variables - * replaced with their respective values and the endpoint of the request appended. - * - * @param endpoint the endpoint to be queried on the server - * @param httpMethod httpMethod to be used - * - */ - public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext { - return new RequestContext(this.getUrl() + endpoint, httpMethod); - } -} - -export const server1 = new ServerConfiguration<{ }>("", { }) - -export const servers = [server1]; diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/types/ObjectParamAPI.ts b/samples/openapi3/client/petstore/typescript/builds/enum/types/ObjectParamAPI.ts deleted file mode 100644 index d3699f9a178..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/types/ObjectParamAPI.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http.ts'; -import { Configuration} from '../configuration.ts' - -import { ChatMessage } from '../models/ChatMessage.ts'; -import { Email } from '../models/Email.ts'; -import { Interaction } from '../models/Interaction.ts'; - -import { ObservableDefaultApi } from "./ObservableAPI.ts"; -import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi.ts"; - -export interface DefaultApiInteractionsGetRequest { - /** - * - * @type string - * @memberof DefaultApiinteractionsGet - */ - parameterTypeMapping?: string -} - -export class ObjectDefaultApi { - private api: ObservableDefaultApi - - public constructor(configuration: Configuration, requestFactory?: DefaultApiRequestFactory, responseProcessor?: DefaultApiResponseProcessor) { - this.api = new ObservableDefaultApi(configuration, requestFactory, responseProcessor); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param param the request object - */ - public interactionsGetWithHttpInfo(param: DefaultApiInteractionsGetRequest = {}, options?: Configuration): Promise> { - return this.api.interactionsGetWithHttpInfo(param.parameterTypeMapping, options).toPromise(); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param param the request object - */ - public interactionsGet(param: DefaultApiInteractionsGetRequest = {}, options?: Configuration): Promise { - return this.api.interactionsGet(param.parameterTypeMapping, options).toPromise(); - } - -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/types/ObservableAPI.ts b/samples/openapi3/client/petstore/typescript/builds/enum/types/ObservableAPI.ts deleted file mode 100644 index ba975047fd7..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/types/ObservableAPI.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http.ts'; -import { Configuration} from '../configuration.ts' -import { Observable, of, from } from '../rxjsStub.ts'; -import {mergeMap, map} from '../rxjsStub.ts'; -import { ChatMessage } from '../models/ChatMessage.ts'; -import { Email } from '../models/Email.ts'; -import { Interaction } from '../models/Interaction.ts'; - -import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi.ts"; -export class ObservableDefaultApi { - private requestFactory: DefaultApiRequestFactory; - private responseProcessor: DefaultApiResponseProcessor; - private configuration: Configuration; - - public constructor( - configuration: Configuration, - requestFactory?: DefaultApiRequestFactory, - responseProcessor?: DefaultApiResponseProcessor - ) { - this.configuration = configuration; - this.requestFactory = requestFactory || new DefaultApiRequestFactory(configuration); - this.responseProcessor = responseProcessor || new DefaultApiResponseProcessor(); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param parameterTypeMapping - */ - public interactionsGetWithHttpInfo(parameterTypeMapping?: string, _options?: Configuration): Observable> { - const requestContextPromise = this.requestFactory.interactionsGet(parameterTypeMapping, _options); - - // build promise chain - let middlewarePreObservable = from(requestContextPromise); - for (const middleware of this.configuration.middleware) { - middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => middleware.pre(ctx))); - } - - return middlewarePreObservable.pipe(mergeMap((ctx: RequestContext) => this.configuration.httpApi.send(ctx))). - pipe(mergeMap((response: ResponseContext) => { - let middlewarePostObservable = of(response); - for (const middleware of this.configuration.middleware) { - middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp: ResponseContext) => middleware.post(rsp))); - } - return middlewarePostObservable.pipe(map((rsp: ResponseContext) => this.responseProcessor.interactionsGetWithHttpInfo(rsp))); - })); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param parameterTypeMapping - */ - public interactionsGet(parameterTypeMapping?: string, _options?: Configuration): Observable { - return this.interactionsGetWithHttpInfo(parameterTypeMapping, _options).pipe(map((apiResponse: HttpInfo) => apiResponse.data)); - } - -} diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/types/PromiseAPI.ts b/samples/openapi3/client/petstore/typescript/builds/enum/types/PromiseAPI.ts deleted file mode 100644 index 82b39fcf219..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/types/PromiseAPI.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { ResponseContext, RequestContext, HttpFile, HttpInfo } from '../http/http.ts'; -import { Configuration} from '../configuration.ts' - -import { ChatMessage } from '../models/ChatMessage.ts'; -import { Email } from '../models/Email.ts'; -import { Interaction } from '../models/Interaction.ts'; -import { ObservableDefaultApi } from './ObservableAPI.ts'; - -import { DefaultApiRequestFactory, DefaultApiResponseProcessor} from "../apis/DefaultApi.ts"; -export class PromiseDefaultApi { - private api: ObservableDefaultApi - - public constructor( - configuration: Configuration, - requestFactory?: DefaultApiRequestFactory, - responseProcessor?: DefaultApiResponseProcessor - ) { - this.api = new ObservableDefaultApi(configuration, requestFactory, responseProcessor); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param parameterTypeMapping - */ - public interactionsGetWithHttpInfo(parameterTypeMapping?: string, _options?: Configuration): Promise> { - const result = this.api.interactionsGetWithHttpInfo(parameterTypeMapping, _options); - return result.toPromise(); - } - - /** - * Optional extended description in Markdown. - * Returns all interactions. - * @param parameterTypeMapping - */ - public interactionsGet(parameterTypeMapping?: string, _options?: Configuration): Promise { - const result = this.api.interactionsGet(parameterTypeMapping, _options); - return result.toPromise(); - } - - -} - - - diff --git a/samples/openapi3/client/petstore/typescript/builds/enum/util.ts b/samples/openapi3/client/petstore/typescript/builds/enum/util.ts deleted file mode 100644 index 96ea3dfdc77..00000000000 --- a/samples/openapi3/client/petstore/typescript/builds/enum/util.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Returns if a specific http code is in a given code range - * where the code range is defined as a combination of digits - * and "X" (the letter X) with a length of 3 - * - * @param codeRange string with length 3 consisting of digits and "X" (the letter X) - * @param code the http status code to be checked against the code range - */ -export function isCodeInRange(codeRange: string, code: number): boolean { - // This is how the default value is encoded in OAG - if (codeRange === "0") { - return true; - } - if (codeRange == code.toString()) { - return true; - } else { - const codeString = code.toString(); - if (codeString.length != codeRange.length) { - return false; - } - for (let i = 0; i < codeString.length; i++) { - if (codeRange.charAt(i) != "X" && codeRange.charAt(i) != codeString.charAt(i)) { - return false; - } - } - return true; - } -} - -/** -* Returns if it can consume form -* -* @param consumes array -*/ -export function canConsumeForm(contentTypes: string[]): boolean { - return contentTypes.indexOf('multipart/form-data') !== -1 -} diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ApiResponse.ts index f4b2d010fb7..3dd68507b21 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Category.ts index 5d63fc87a99..e025011174d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts index 97a82f53c20..ec528248327 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 4d80550bb2a..b8d4a26c7d4 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 ecaefffea4f..ddb68aa82a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Tag.ts index 8c4f6967b9a..7a7a36ba59a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/models/User.ts index 68528ad3c9e..4dbe18f7fed 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ApiResponse.ts index f4b2d010fb7..3dd68507b21 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Category.ts index 5d63fc87a99..e025011174d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts index 97a82f53c20..ec528248327 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 4d80550bb2a..b8d4a26c7d4 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Order.ts @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 ecaefffea4f..ddb68aa82a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Tag.ts index 8c4f6967b9a..7a7a36ba59a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/models/User.ts index 68528ad3c9e..4dbe18f7fed 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ApiResponse.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ApiResponse.ts index f4b2d010fb7..3dd68507b21 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ApiResponse.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ApiResponse.ts @@ -22,6 +22,8 @@ export class ApiResponse { 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": "code", @@ -49,4 +51,3 @@ export class ApiResponse { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Category.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Category.ts index 5d63fc87a99..e025011174d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Category.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Category.ts @@ -21,6 +21,8 @@ export class Category { 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": "id", @@ -42,4 +44,3 @@ export class Category { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts index 97a82f53c20..ec528248327 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/ObjectSerializer.ts @@ -114,8 +114,11 @@ export class ObjectSerializer { } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; } else { return expectedType; // discriminator did not map to a type } 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 4d80550bb2a..b8d4a26c7d4 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 @@ -28,6 +28,8 @@ export class Order { 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": "id", @@ -74,7 +76,6 @@ export class Order { } } - export enum OrderStatusEnum { Placed = 'placed', Approved = 'approved', 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 ecaefffea4f..ddb68aa82a1 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 @@ -30,6 +30,8 @@ export class Pet { 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": "id", @@ -76,7 +78,6 @@ export class Pet { } } - export enum PetStatusEnum { Available = 'available', Pending = 'pending', diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Tag.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Tag.ts index 8c4f6967b9a..7a7a36ba59a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/Tag.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/Tag.ts @@ -21,6 +21,8 @@ export class Tag { 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": "id", @@ -42,4 +44,3 @@ export class Tag { public constructor() { } } - diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/models/User.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/models/User.ts index 68528ad3c9e..4dbe18f7fed 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/models/User.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/models/User.ts @@ -30,6 +30,8 @@ export class User { 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": "id", @@ -87,4 +89,3 @@ export class User { public constructor() { } } -