Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,12 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
// set boolean flag (e.g. isString)
setParameterBooleanFlagWithCodegenProperty(p, cp);

p.dataType = cp.datatype;
String parameterDataType = this.getParameterDataType(param, property);
if (parameterDataType != null) {
p.dataType = parameterDataType;
} else {
p.dataType = cp.datatype;
}
p.dataFormat = cp.dataFormat;
if(cp.isEnum) {
p.datatypeWithEnum = cp.datatypeWithEnum;
Expand Down Expand Up @@ -2719,6 +2724,18 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
return p;
}

/**
* Returns the data type of a parameter.
* Returns null by default to use the CodegenProperty.datatype value
* @param parameter
* @param property
* @return
*/
protected String getParameterDataType(Parameter parameter, Property property) {
return null;
}


public boolean isDataTypeBinary(String dataType) {
if (dataType != null) {
return dataType.toLowerCase().startsWith("byte");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package io.swagger.codegen.languages;

import io.swagger.models.parameters.Parameter;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.*;

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
Expand Down Expand Up @@ -234,6 +230,101 @@ public String getTypeDeclaration(Property p) {
return super.getTypeDeclaration(p);
}


@Override
protected String getParameterDataType(Parameter parameter, Property p) {
// handle enums of various data types
Property inner;
if (p instanceof ArrayProperty) {
ArrayProperty mp1 = (ArrayProperty) p;
inner = mp1.getItems();
return this.getSwaggerType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
inner = mp.getAdditionalProperties();
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
} else if (p instanceof StringProperty) {
// Handle string enums
StringProperty sp = (StringProperty) p;
if (sp.getEnum() != null) {
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
}
} else if (p instanceof IntegerProperty) {
// Handle integer enums
IntegerProperty sp = (IntegerProperty) p;
if (sp.getEnum() != null) {
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(sp.getEnum()));
}
} else if (p instanceof LongProperty) {
// Handle long enums
LongProperty sp = (LongProperty) p;
if (sp.getEnum() != null) {
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(sp.getEnum()));
}
} else if (p instanceof DoubleProperty) {
// Handle double enums
DoubleProperty sp = (DoubleProperty) p;
if (sp.getEnum() != null) {
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(sp.getEnum()));
}
} else if (p instanceof FloatProperty) {
// Handle float enums
FloatProperty sp = (FloatProperty) p;
if (sp.getEnum() != null) {
return numericEnumValuesToEnumTypeUnion(new ArrayList<Number>(sp.getEnum()));
}
} else if (p instanceof DateProperty) {
// Handle date enums
DateProperty sp = (DateProperty) p;
if (sp.getEnum() != null) {
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
}
} else if (p instanceof DateTimeProperty) {
// Handle datetime enums
DateTimeProperty sp = (DateTimeProperty) p;
if (sp.getEnum() != null) {
return enumValuesToEnumTypeUnion(sp.getEnum(), "string");
}
}
return this.getTypeDeclaration(p);
}

/**
* Converts a list of strings to a literal union for representing enum values as a type.
* Example output: 'available' | 'pending' | 'sold'
*
* @param values list of allowed enum values
* @param dataType either "string" or "number"
* @return
*/
protected String enumValuesToEnumTypeUnion(List<String> values, String dataType) {
StringBuilder b = new StringBuilder();
boolean isFirst = true;
for (String value: values) {
if (!isFirst) {
b.append(" | ");
}
b.append(toEnumValue(value.toString(), dataType));
isFirst = false;
}
return b.toString();
}

/**
* Converts a list of numbers to a literal union for representing enum values as a type.
* Example output: 3 | 9 | 55
*
* @param values
* @return
*/
protected String numericEnumValuesToEnumTypeUnion(List<Number> values) {
List<String> stringValues = new ArrayList<>();
for (Number value: values) {
stringValues.add(value.toString());
}
return enumValuesToEnumTypeUnion(stringValues, "number");
}

@Override
public String toDefaultValue(Property p) {
if (p instanceof StringProperty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
import io.swagger.codegen.SupportingFile;
import io.swagger.codegen.utils.SemVer;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.*;

public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
Expand Down Expand Up @@ -161,16 +156,7 @@ public boolean isDataTypeFile(final String dataType) {

@Override
public String getTypeDeclaration(Property p) {
Property inner;
if (p instanceof ArrayProperty) {
ArrayProperty mp1 = (ArrayProperty) p;
inner = mp1.getItems();
return this.getSwaggerType(p) + "<" + this.getTypeDeclaration(inner) + ">";
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
inner = mp.getAdditionalProperties();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else if (p instanceof FileProperty) {
if (p instanceof FileProperty) {
return "Blob";
} else if (p instanceof ObjectProperty) {
return "any";
Expand All @@ -179,6 +165,7 @@ public String getTypeDeclaration(Property p) {
}
}


@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1-SNAPSHOT
2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PetService {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export class PetService {
* @param status Status values that need to be considered for filter

*/
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
public findPetsByStatusWithHttpInfo(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1-SNAPSHOT
2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PetService {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export class PetService {
* @param status Status values that need to be considered for filter

*/
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
public findPetsByStatusWithHttpInfo(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1-SNAPSHOT
2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class PetService implements PetServiceInterface {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
Expand Down Expand Up @@ -306,7 +306,7 @@ export class PetService implements PetServiceInterface {
* @param status Status values that need to be considered for filter

*/
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
public findPetsByStatusWithHttpInfo(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface PetServiceInterface {
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for filter
*/
findPetsByStatus(status: Array<string>, extraHttpRequestParams?: any): Observable<Array<Pet>>;
findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: any): Observable<Array<Pet>>;

/**
* Finds Pets by tags
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1-SNAPSHOT
2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ export class PetService {
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public findPetsByStatus(status: Array<string>, observe?: 'body', reportProgress?: boolean): Observable<Array<Pet>>;
public findPetsByStatus(status: Array<string>, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<Array<Pet>>>;
public findPetsByStatus(status: Array<string>, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<Array<Pet>>>;
public findPetsByStatus(status: Array<string>, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, observe?: 'body', reportProgress?: boolean): Observable<Array<Pet>>;
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<Array<Pet>>>;
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<Array<Pet>>>;
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1-SNAPSHOT
2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PetService {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Array<Pet>> {
return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export class PetService {
* @param status Status values that need to be considered for filter

*/
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
public findPetsByStatusWithHttpInfo(status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.3.1
18 changes: 9 additions & 9 deletions samples/client/petstore/typescript-angularjs/api/PetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class PetApi {
method: 'POST',
url: localVarPath,
data: body,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand Down Expand Up @@ -77,7 +77,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'DELETE',
url: localVarPath,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand All @@ -92,7 +92,7 @@ export class PetApi {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus (status: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<models.Pet>> {
public findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<models.Pet>> {
const localVarPath = this.basePath + '/pet/findByStatus';

let queryParameters: any = {};
Expand All @@ -109,7 +109,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand Down Expand Up @@ -141,7 +141,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand Down Expand Up @@ -170,7 +170,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand Down Expand Up @@ -199,7 +199,7 @@ export class PetApi {
method: 'PUT',
url: localVarPath,
data: body,
params: queryParameters,
params: queryParameters,
headers: headerParams
};

Expand Down Expand Up @@ -238,7 +238,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
data: this.$httpParamSerializer(formParams),
data: this.$httpParamSerializer(formParams),
params: queryParameters,
headers: headerParams
};
Expand Down Expand Up @@ -278,7 +278,7 @@ export class PetApi {
let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
data: this.$httpParamSerializer(formParams),
data: this.$httpParamSerializer(formParams),
params: queryParameters,
headers: headerParams
};
Expand Down
Loading