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 ff2622c563d..78eae0ec438 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache @@ -28,7 +28,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{/discriminator}} {{^isArrayModel}} - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ {{#vars}} { "name": "{{name}}", @@ -48,6 +48,20 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{/parent}} } {{/isArrayModel}} + + public constructor() { + {{#parent}} + super(); + {{/parent}} + {{#allVars}} + {{#discriminatorValue}} + this.{{name}} = "{{discriminatorValue}}"; + {{/discriminatorValue}} + {{/allVars}} + {{#discriminatorName}} + this.{{discriminatorName}} = "{{classname}}"; + {{/discriminatorName}} + } } {{#hasEnums}} diff --git a/samples/client/petstore/typescript/builds/default/models/ApiResponse.ts b/samples/client/petstore/typescript/builds/default/models/ApiResponse.ts index f8f40e52154..cc919118ae7 100644 --- a/samples/client/petstore/typescript/builds/default/models/ApiResponse.ts +++ b/samples/client/petstore/typescript/builds/default/models/ApiResponse.ts @@ -12,7 +12,7 @@ export class ApiResponse { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "code", "baseName": "code", @@ -32,5 +32,8 @@ export class ApiResponse { static getAttributeTypeMap() { return ApiResponse.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/Cat.ts b/samples/client/petstore/typescript/builds/default/models/Cat.ts new file mode 100644 index 00000000000..7474d1a8ad6 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/models/Cat.ts @@ -0,0 +1,36 @@ +/* + TODO: LICENSE INFO +*/ +import { Pet2 } from './Pet2'; + +/** +* A representation of a cat +*/ +export class Cat extends Pet2 { + /** + * The measured skill for hunting + */ + 'huntingSkill': CatHuntingSkillEnum; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "huntingSkill", + "baseName": "huntingSkill", + "type": "CatHuntingSkillEnum" + } ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(Cat.attributeTypeMap); + } + + public constructor() { + super(); + this.petType = "Cat"; + } +} + + +export type CatHuntingSkillEnum = "clueless" | "lazy" | "adventurous" | "aggressive" ; + diff --git a/samples/client/petstore/typescript/builds/default/models/Category.ts b/samples/client/petstore/typescript/builds/default/models/Category.ts index 3520fde26a5..af9bdf34d54 100644 --- a/samples/client/petstore/typescript/builds/default/models/Category.ts +++ b/samples/client/petstore/typescript/builds/default/models/Category.ts @@ -11,7 +11,7 @@ export class Category { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "id", "baseName": "id", @@ -26,5 +26,8 @@ export class Category { static getAttributeTypeMap() { return Category.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/Dog.ts b/samples/client/petstore/typescript/builds/default/models/Dog.ts new file mode 100644 index 00000000000..27db6214430 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/models/Dog.ts @@ -0,0 +1,33 @@ +/* + TODO: LICENSE INFO +*/ +import { Pet2 } from './Pet2'; + +/** +* A representation of a dog +*/ +export class Dog extends Pet2 { + /** + * the size of the pack the dog is from + */ + 'packSize': number; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "packSize", + "baseName": "packSize", + "type": "number" + } ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(Dog.attributeTypeMap); + } + + public constructor() { + super(); + this.petType = "Dog"; + } +} + diff --git a/samples/client/petstore/typescript/builds/default/models/ErrorModel.ts b/samples/client/petstore/typescript/builds/default/models/ErrorModel.ts new file mode 100644 index 00000000000..9dc7a6e1ae4 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/models/ErrorModel.ts @@ -0,0 +1,30 @@ +/* + TODO: LICENSE INFO +*/ + +export class ErrorModel { + 'message': string; + 'code': number; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "message", + "baseName": "message", + "type": "string" + }, + { + "name": "code", + "baseName": "code", + "type": "number" + } ]; + + static getAttributeTypeMap() { + return ErrorModel.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/samples/client/petstore/typescript/builds/default/models/ExtendedErrorModel.ts b/samples/client/petstore/typescript/builds/default/models/ExtendedErrorModel.ts new file mode 100644 index 00000000000..cf0b46b68f1 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/models/ExtendedErrorModel.ts @@ -0,0 +1,26 @@ +/* + TODO: LICENSE INFO +*/ +import { ErrorModel } from './ErrorModel'; + +export class ExtendedErrorModel extends ErrorModel { + 'rootCause': string; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "rootCause", + "baseName": "rootCause", + "type": "string" + } ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(ExtendedErrorModel.attributeTypeMap); + } + + public constructor() { + super(); + } +} + diff --git a/samples/client/petstore/typescript/builds/default/models/ObjectSerializer.ts b/samples/client/petstore/typescript/builds/default/models/ObjectSerializer.ts index 6e0c08a9baf..b5bac247746 100644 --- a/samples/client/petstore/typescript/builds/default/models/ObjectSerializer.ts +++ b/samples/client/petstore/typescript/builds/default/models/ObjectSerializer.ts @@ -1,14 +1,24 @@ export * from './ApiResponse'; +export * from './Cat'; export * from './Category'; +export * from './Dog'; +export * from './ErrorModel'; +export * from './ExtendedErrorModel'; export * from './Order'; export * from './Pet'; +export * from './Pet2'; export * from './Tag'; export * from './User'; import { ApiResponse } from './ApiResponse'; +import { Cat, CatHuntingSkillEnum } from './Cat'; import { Category } from './Category'; +import { Dog } from './Dog'; +import { ErrorModel } from './ErrorModel'; +import { ExtendedErrorModel } from './ExtendedErrorModel'; import { Order , OrderStatusEnum } from './Order'; import { Pet , PetStatusEnum } from './Pet'; +import { Pet2 } from './Pet2'; import { Tag } from './Tag'; import { User } from './User'; @@ -25,15 +35,21 @@ let primitives = [ ]; let enumsMap: Set = new Set([ + "CatHuntingSkillEnum", "OrderStatusEnum", "PetStatusEnum", ]); let typeMap: {[index: string]: any} = { "ApiResponse": ApiResponse, + "Cat": Cat, "Category": Category, + "Dog": Dog, + "ErrorModel": ErrorModel, + "ExtendedErrorModel": ExtendedErrorModel, "Order": Order, "Pet": Pet, + "Pet2": Pet2, "Tag": Tag, "User": User, } diff --git a/samples/client/petstore/typescript/builds/default/models/Order.ts b/samples/client/petstore/typescript/builds/default/models/Order.ts index 049cb8c7140..f4d97a72987 100644 --- a/samples/client/petstore/typescript/builds/default/models/Order.ts +++ b/samples/client/petstore/typescript/builds/default/models/Order.ts @@ -18,7 +18,7 @@ export class Order { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "id", "baseName": "id", @@ -53,6 +53,9 @@ export class Order { static getAttributeTypeMap() { return Order.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/Pet.ts b/samples/client/petstore/typescript/builds/default/models/Pet.ts index 6dc00c53671..5ecf6920762 100644 --- a/samples/client/petstore/typescript/builds/default/models/Pet.ts +++ b/samples/client/petstore/typescript/builds/default/models/Pet.ts @@ -20,7 +20,7 @@ export class Pet { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "id", "baseName": "id", @@ -55,6 +55,9 @@ export class Pet { static getAttributeTypeMap() { return Pet.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/Pet2.ts b/samples/client/petstore/typescript/builds/default/models/Pet2.ts new file mode 100644 index 00000000000..865be4493a5 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/models/Pet2.ts @@ -0,0 +1,31 @@ +/* + TODO: LICENSE INFO +*/ + +export class Pet2 { + 'name': string; + 'petType': string; + + static readonly discriminator: string | undefined = "petType"; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "name", + "baseName": "name", + "type": "string" + }, + { + "name": "petType", + "baseName": "petType", + "type": "string" + } ]; + + static getAttributeTypeMap() { + return Pet2.attributeTypeMap; + } + + public constructor() { + this.petType = "Pet2"; + } +} + diff --git a/samples/client/petstore/typescript/builds/default/models/Tag.ts b/samples/client/petstore/typescript/builds/default/models/Tag.ts index 1d11453712e..044e5f8d236 100644 --- a/samples/client/petstore/typescript/builds/default/models/Tag.ts +++ b/samples/client/petstore/typescript/builds/default/models/Tag.ts @@ -11,7 +11,7 @@ export class Tag { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "id", "baseName": "id", @@ -26,5 +26,8 @@ export class Tag { static getAttributeTypeMap() { return Tag.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/User.ts b/samples/client/petstore/typescript/builds/default/models/User.ts index d9510f87ca9..d29220a33eb 100644 --- a/samples/client/petstore/typescript/builds/default/models/User.ts +++ b/samples/client/petstore/typescript/builds/default/models/User.ts @@ -20,7 +20,7 @@ export class User { static readonly discriminator: string | undefined = undefined; - private static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ { "name": "id", "baseName": "id", @@ -65,5 +65,8 @@ export class User { static getAttributeTypeMap() { return User.attributeTypeMap; } + + public constructor() { + } } diff --git a/samples/client/petstore/typescript/builds/default/models/all.ts b/samples/client/petstore/typescript/builds/default/models/all.ts index 2edba7f0bd5..5b69a96a602 100644 --- a/samples/client/petstore/typescript/builds/default/models/all.ts +++ b/samples/client/petstore/typescript/builds/default/models/all.ts @@ -1,6 +1,11 @@ export * from './ApiResponse' +export * from './Cat' export * from './Category' +export * from './Dog' +export * from './ErrorModel' +export * from './ExtendedErrorModel' export * from './Order' export * from './Pet' +export * from './Pet2' export * from './Tag' export * from './User' diff --git a/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts b/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts index 8499e8bacad..30171cf9f08 100644 --- a/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts +++ b/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts @@ -5,9 +5,14 @@ import { Observable, of } from 'rxjs'; import {mergeMap, map} from 'rxjs/operators'; import { ApiResponse } from '../models/ApiResponse'; +import { Cat } from '../models/Cat'; import { Category } from '../models/Category'; +import { Dog } from '../models/Dog'; +import { ErrorModel } from '../models/ErrorModel'; +import { ExtendedErrorModel } from '../models/ExtendedErrorModel'; import { Order } from '../models/Order'; import { Pet } from '../models/Pet'; +import { Pet2 } from '../models/Pet2'; import { Tag } from '../models/Tag'; import { User } from '../models/User'; diff --git a/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts b/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts index c449b9e5b8e..f2d947179b9 100644 --- a/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts +++ b/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts @@ -3,9 +3,14 @@ import * as models from '../models/all'; import { Configuration} from '../configuration' import { ApiResponse } from '../models/ApiResponse'; +import { Cat } from '../models/Cat'; import { Category } from '../models/Category'; +import { Dog } from '../models/Dog'; +import { ErrorModel } from '../models/ErrorModel'; +import { ExtendedErrorModel } from '../models/ExtendedErrorModel'; import { Order } from '../models/Order'; import { Pet } from '../models/Pet'; +import { Pet2 } from '../models/Pet2'; import { Tag } from '../models/Tag'; import { User } from '../models/User'; import { ObservablePetApi } from './ObservableAPI';