diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java index 5389c509d76d..0676372e64a7 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -59,6 +59,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp //TODO binary should be mapped to byte array // mapped to String as a workaround typeMapping.put("binary", "string"); + typeMapping.put("ByteArray", "string"); cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase")); diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index 630b2c03d1e9..dd66a09dcb7b 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -25,16 +25,30 @@ export class Dog extends Animal { "breed": string; } +export class FormatTest { + "integer": number; + "int32": number; + "int64": number; + "number": number; + "float": number; + "double": number; + "string": string; + "byte": string; + "binary": string; + "date": Date; + "dateTime": string; +} + export class InlineResponse200 { - "photoUrls": Array; - "name": string; + "tags": Array; "id": number; "category": any; - "tags": Array; /** * pet status in the store */ "status": InlineResponse200.StatusEnum; + "name": string; + "photoUrls": Array; } export namespace InlineResponse200 { @@ -176,27 +190,21 @@ class VoidAuth implements Authentication { } } -export enum PetApiApiKeys { - test_api_client_id, - test_api_client_secret, - api_key, - test_api_key_query, - test_api_key_header, -} - export class PetApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; - protected authentications = { + + + public authentications = { 'default': new VoidAuth(), - 'petstore_auth': new OAuth(), - 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), - 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), 'test_http_basic': new HttpBasicAuth(), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), - 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), + 'petstore_auth': new OAuth(), } constructor(basePath?: string); @@ -215,12 +223,12 @@ export class PetApi { } } - public setApiKey(key: PetApiApiKeys, value: string) { - this.authentications[PetApiApiKeys[key]].apiKey = value; + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; } - set accessToken(token: string) { - this.authentications.petstore_auth.accessToken = token; + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; } set username(username: string) { @@ -230,6 +238,22 @@ export class PetApi { set password(password: string) { this.authentications.test_http_basic.password = password; } + + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -295,7 +319,7 @@ export class PetApi { * @param body Pet object in the form of byte array */ public addPetUsingByteArray (body?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const localVarPath = this.basePath + '/pet?testing_byte_array=true'; + const localVarPath = this.basePath + '/pet?testing_byte_array=true'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -537,10 +561,10 @@ export class PetApi { json: true, } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -571,7 +595,7 @@ export class PetApi { * @param petId ID of pet that needs to be fetched */ public getPetByIdInObject (petId: number) : Promise<{ response: http.ClientResponse; body: InlineResponse200; }> { - const localVarPath = this.basePath + '/pet/{petId}?response=inline_arbitrary_object' + const localVarPath = this.basePath + '/pet/{petId}?response=inline_arbitrary_object' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -595,10 +619,10 @@ export class PetApi { json: true, } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -629,7 +653,7 @@ export class PetApi { * @param petId ID of pet that needs to be fetched */ public petPetIdtestingByteArraytrueGet (petId: number) : Promise<{ response: http.ClientResponse; body: string; }> { - const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array=true' + const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array=true' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -653,10 +677,10 @@ export class PetApi { json: true, } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -866,27 +890,21 @@ export class PetApi { return localVarDeferred.promise; } } -export enum StoreApiApiKeys { - test_api_client_id, - test_api_client_secret, - api_key, - test_api_key_query, - test_api_key_header, -} - export class StoreApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; - protected authentications = { + + + public authentications = { 'default': new VoidAuth(), - 'petstore_auth': new OAuth(), - 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), - 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), 'test_http_basic': new HttpBasicAuth(), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), - 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), + 'petstore_auth': new OAuth(), } constructor(basePath?: string); @@ -905,12 +923,12 @@ export class StoreApi { } } - public setApiKey(key: StoreApiApiKeys, value: string) { - this.authentications[StoreApiApiKeys[key]].apiKey = value; + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; } - set accessToken(token: string) { - this.authentications.petstore_auth.accessToken = token; + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; } set username(username: string) { @@ -920,6 +938,22 @@ export class StoreApi { set password(password: string) { this.authentications.test_http_basic.password = password; } + + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -1092,7 +1126,7 @@ export class StoreApi { * Returns an arbitrary object which is actually a map of status codes to quantities */ public getInventoryInObject () : Promise<{ response: http.ClientResponse; body: any; }> { - const localVarPath = this.basePath + '/store/inventory?response=arbitrary_object'; + const localVarPath = this.basePath + '/store/inventory?response=arbitrary_object'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -1138,7 +1172,7 @@ export class StoreApi { } /** * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { @@ -1166,10 +1200,10 @@ export class StoreApi { json: true, } - this.authentications.test_api_key_query.applyToRequest(requestOptions); - this.authentications.test_api_key_header.applyToRequest(requestOptions); + this.authentications.test_api_key_query.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1248,27 +1282,21 @@ export class StoreApi { return localVarDeferred.promise; } } -export enum UserApiApiKeys { - test_api_client_id, - test_api_client_secret, - api_key, - test_api_key_query, - test_api_key_header, -} - export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; - protected authentications = { + + + public authentications = { 'default': new VoidAuth(), - 'petstore_auth': new OAuth(), - 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), - 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), 'test_http_basic': new HttpBasicAuth(), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), - 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), + 'petstore_auth': new OAuth(), } constructor(basePath?: string); @@ -1287,12 +1315,12 @@ export class UserApi { } } - public setApiKey(key: UserApiApiKeys, value: string) { - this.authentications[UserApiApiKeys[key]].apiKey = value; + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; } - set accessToken(token: string) { - this.authentications.petstore_auth.accessToken = token; + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; } set username(username: string) { @@ -1302,6 +1330,22 @@ export class UserApi { set password(password: string) { this.authentications.test_http_basic.password = password; } + + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){