add prefix, suffix to ts model

This commit is contained in:
wing328 2016-02-29 12:11:54 +08:00
parent 9f3c34dbfa
commit 74d91f4ea1
9 changed files with 400 additions and 224 deletions

View File

@ -17,12 +17,13 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
supportsInheritance = true;
setReservedWordsLowerCase(Arrays.asList(
// local variable names used in API methods (endpoints)
"path", "queryParameters", "headerParams", "formParams", "useFormData", "deferred",
"varLocalPath", "queryParameters", "headerParams", "formParams", "useFormData", "varLocalDeferred",
"requestOptions",
// Typescript reserved words
"abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"));
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
"string",
"String",
"boolean",
"Boolean",
@ -30,7 +31,12 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
"Integer",
"Long",
"Float",
"Object"));
"Object",
"Array",
"Date",
"number",
"any"
));
instantiationTypes.put("array", "Array");
typeMapping = new HashMap<String, String>();
@ -116,10 +122,22 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
@Override
public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name))
throw new RuntimeException(name
+ " (reserved word) cannot be used as a model name");
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = camelize("object_" + name);
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}
// camelize the model name
// phone_number => PhoneNumber
@ -158,7 +176,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
return type;
} else
type = swaggerType;
return type;
return toModelName(type);
}
@Override

View File

@ -39,7 +39,7 @@ namespace {{package}} {
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
const path = this.basePath + '{{path}}'{{#pathParams}}
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {};
@ -76,7 +76,7 @@ namespace {{package}} {
{{/formParams}}
let httpRequestParams: any = {
method: '{{httpMethod}}',
url: path,
url: localVarPath,
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
{{#bodyParam}}data: {{paramName}},
{{/bodyParam}}

View File

@ -179,7 +179,7 @@ export class {{classname}} {
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
const path = this.basePath + '{{path}}'{{#pathParams}}
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -212,13 +212,13 @@ export class {{classname}} {
{{/isFile}}
{{/formParams}}
let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>();
let localVarDeferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>();
let requestOptions: request.Options = {
method: '{{httpMethod}}',
qs: queryParameters,
headers: headerParams,
uri: path,
uri: localVarPath,
json: true,
{{#bodyParam}}
body: {{paramName}},
@ -241,17 +241,17 @@ export class {{classname}} {
request(requestOptions, (error, response, body) => {
if (error) {
deferred.reject(error);
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({ response: response, body: body });
localVarDeferred.resolve({ response: response, body: body });
} else {
deferred.reject({ response: response, body: body });
localVarDeferred.reject({ response: response, body: body });
}
}
});
return deferred.promise;
return localVarDeferred.promise;
}
{{/operation}}
}

View File

@ -59,7 +59,7 @@ public class TypeScriptAngularModelTest {
final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.complexType, "Date");
Assert.assertEquals(property3.complexType, null);
Assert.assertEquals(property3.datatype, "Date");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");

View File

@ -59,7 +59,7 @@ public class TypeScriptNodeModelTest {
final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.complexType, "Date");
Assert.assertEquals(property3.complexType, null);
Assert.assertEquals(property3.datatype, "Date");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");

View File

@ -32,13 +32,13 @@ namespace API.Client {
* @param body Pet object that needs to be added to the store
*/
public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet';
const localVarPath = this.basePath + '/pet';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'PUT',
url: path,
url: localVarPath,
json: true,
data: body,
@ -59,13 +59,13 @@ namespace API.Client {
* @param body Pet object that needs to be added to the store
*/
public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet';
const localVarPath = this.basePath + '/pet';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -82,11 +82,11 @@ namespace API.Client {
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query
*/
public findPetsByStatus (status?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
const path = this.basePath + '/pet/findByStatus';
const localVarPath = this.basePath + '/pet/findByStatus';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -96,7 +96,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -116,7 +116,7 @@ namespace API.Client {
* @param tags Tags to filter by
*/
public findPetsByTags (tags?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
const path = this.basePath + '/pet/findByTags';
const localVarPath = this.basePath + '/pet/findByTags';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -126,7 +126,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -146,7 +146,7 @@ namespace API.Client {
* @param petId ID of pet that needs to be fetched
*/
public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<Pet> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -157,7 +157,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -179,7 +179,7 @@ namespace API.Client {
* @param status Updated status of the pet
*/
public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -198,7 +198,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
@ -220,7 +220,7 @@ namespace API.Client {
* @param apiKey
*/
public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -233,7 +233,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,
@ -255,7 +255,7 @@ namespace API.Client {
* @param file file to upload
*/
public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}/uploadImage'
const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -274,7 +274,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
@ -294,19 +294,19 @@ namespace API.Client {
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
*/
public getPetByIdWithByteArray (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const path = this.basePath + '/pet/{petId}?testing_byte_array=true'
public petPetIdtestingByteArraytrueGet (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array=true'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
// verify required parameter 'petId' is set
if (!petId) {
throw new Error('Missing required parameter petId when calling getPetByIdWithByteArray');
throw new Error('Missing required parameter petId when calling petPetIdtestingByteArraytrueGet');
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -326,13 +326,13 @@ namespace API.Client {
* @param body Pet object in the form of byte array
*/
public addPetUsingByteArray (body?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = 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 httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,

View File

@ -26,18 +26,48 @@ namespace API.Client {
return <T1&T2>objA;
}
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query
*/
public findOrdersByStatus (status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Order>> {
const localVarPath = this.basePath + '/store/findByStatus';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
if (status !== undefined) {
queryParameters['status'] = status;
}
let httpRequestParams: any = {
method: 'GET',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};
if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
}
return this.$http(httpRequestParams);
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
*/
public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> {
const path = this.basePath + '/store/inventory';
const localVarPath = this.basePath + '/store/inventory';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -57,13 +87,13 @@ namespace API.Client {
* @param body order placed for purchasing the pet
*/
public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
const path = this.basePath + '/store/order';
const localVarPath = this.basePath + '/store/order';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -84,7 +114,7 @@ namespace API.Client {
* @param orderId ID of pet that needs to be fetched
*/
public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
const path = this.basePath + '/store/order/{orderId}'
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
let queryParameters: any = {};
@ -95,7 +125,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -115,7 +145,7 @@ namespace API.Client {
* @param orderId ID of the order that needs to be deleted
*/
public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/store/order/{orderId}'
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
let queryParameters: any = {};
@ -126,7 +156,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,

View File

@ -32,13 +32,13 @@ namespace API.Client {
* @param body Created user object
*/
public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user';
const localVarPath = this.basePath + '/user';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -59,13 +59,13 @@ namespace API.Client {
* @param body List of user object
*/
public createUsersWithArrayInput (body?: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/createWithArray';
const localVarPath = this.basePath + '/user/createWithArray';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -86,13 +86,13 @@ namespace API.Client {
* @param body List of user object
*/
public createUsersWithListInput (body?: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/createWithList';
const localVarPath = this.basePath + '/user/createWithList';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -114,7 +114,7 @@ namespace API.Client {
* @param password The password for login in clear text
*/
public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const path = this.basePath + '/user/login';
const localVarPath = this.basePath + '/user/login';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -128,7 +128,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -147,13 +147,13 @@ namespace API.Client {
*
*/
public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/logout';
const localVarPath = this.basePath + '/user/logout';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -173,7 +173,7 @@ namespace API.Client {
* @param username The name that needs to be fetched. Use user1 for testing.
*/
public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<User> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -184,7 +184,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -205,7 +205,7 @@ namespace API.Client {
* @param body Updated user object
*/
public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -216,7 +216,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'PUT',
url: path,
url: localVarPath,
json: true,
data: body,
@ -237,7 +237,7 @@ namespace API.Client {
* @param username The name that needs to be deleted
*/
public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -248,7 +248,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,

File diff suppressed because it is too large Load Diff