[typescript-angular2] Feature/angular2 file post (#4623)

* Merge branch 'www2k-feature/file-response'

* Merge pull request #4421 from wing328/fix_isfile_boolean

Fix `isPrimitiveType` for file property

* roll back to latest working version of swagger paresr for codegen

* enable typescript-angular2 to upload file

* update typescript-angular2 samples
This commit is contained in:
wing328 2017-01-23 18:28:13 +08:00 committed by GitHub
parent 4034ee0e3e
commit 4fcef31b6b
9 changed files with 215 additions and 191 deletions

View File

@ -41,7 +41,9 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
embeddedTemplateDir = templateDir = "typescript-angular2";
modelTemplateFiles.put("model.mustache", ".ts");
apiTemplateFiles.put("api.service.mustache", ".ts");
languageSpecificPrimitives.add("Blob");
typeMapping.put("Date","Date");
typeMapping.put("file","Blob");
apiPackage = "api";
modelPackage = "model";
@ -116,6 +118,11 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
return indexPackage.replace('.', File.separatorChar);
}
@Override
public boolean isDataTypeFile(final String dataType) {
return dataType != null && dataType.equals("Blob");
}
@Override
public String getTypeDeclaration(Property p) {
Property inner;
@ -127,7 +134,9 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
MapProperty mp = (MapProperty)p;
inner = mp.getAdditionalProperties();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else if(p instanceof FileProperty || p instanceof ObjectProperty) {
} else if(p instanceof FileProperty) {
return "Blob";
} else if(p instanceof ObjectProperty) {
return "any";
} else {
return super.getTypeDeclaration(p);

View File

@ -54,6 +54,20 @@ export class {{classname}} {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
{{#operation}}
/**
* {{summary}}
@ -66,7 +80,12 @@ export class {{classname}} {
if (response.status === 204) {
return undefined;
} else {
{{^isResponseFile}}
return response.json();
{{/isResponseFile}}
{{#isResponseFile}}
return response.blob();
{{/isResponseFile}}
}
});
}
@ -84,10 +103,7 @@ export class {{classname}} {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
{{#hasFormParams}}
let formParams = new URLSearchParams();
{{/hasFormParams}}
{{#allParams}}
{{#required}}
// verify required parameter '{{paramName}}' is not null or undefined
@ -106,12 +122,24 @@ export class {{classname}} {
headers.set('{{baseName}}', String({{paramName}}));
{{/headerParams}}
{{#hasFormParams}}
// to determine the Content-Type header
let consumes: string[] = [
{{#consumes}}
'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}
{{/consumes}}
];
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
{{#formParams}}
{{#isFile}}
useForm = canConsumeForm;
{{/isFile}}
{{/formParams}}
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
{{/hasFormParams}}
// to determine the Accept header
let produces: string[] = [
@ -155,17 +183,13 @@ export class {{classname}} {
{{/isOAuth}}
{{/authMethods}}
{{#hasFormParams}}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
{{/hasFormParams}}
{{#bodyParam}}
headers.set('Content-Type', 'application/json');
{{/bodyParam}}
{{#formParams}}
if ({{paramName}} !== undefined) {
formParams.set('{{baseName}}', <any>{{paramName}});
formParams.set('{{baseName}}', {{paramName}});
}
{{/formParams}}
@ -176,8 +200,11 @@ export class {{classname}} {
body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612
{{/bodyParam}}
{{#hasFormParams}}
body: formParams.toString(),
body: formParams,
{{/hasFormParams}}
{{#isResponseFile}}
responseType: ResponseContentType.Blob,
{{/isResponseFile}}
search: queryParameters
});

View File

@ -57,6 +57,20 @@ export class PetService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Add a new pet to the store
*
@ -179,7 +193,7 @@ export class PetService {
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<{}> {
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<{}> {
return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
@ -203,11 +217,7 @@ export class PetService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/xml'
];
// to determine the Accept header
let produces: string[] = [
@ -225,7 +235,6 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/json');
@ -255,6 +264,7 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
@ -262,9 +272,6 @@ export class PetService {
headers.set('api_key', String(apiKey));
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -284,7 +291,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -309,14 +315,12 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (status !== undefined) {
queryParameters.set('status', <any>status);
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -336,7 +340,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -361,14 +364,12 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (tags !== undefined) {
queryParameters.set('tags', <any>tags);
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -388,7 +389,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -413,15 +413,13 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling getPetById.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -443,10 +441,14 @@ export class PetService {
{
headers.set('api_key', this.configuration.apiKey);
}
// authentication (api_key) required
if (this.configuration.apiKey)
{
headers.set('api_key', this.configuration.apiKey);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -473,11 +475,7 @@ export class PetService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/xml'
];
// to determine the Accept header
let produces: string[] = [
@ -495,7 +493,6 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/json');
@ -526,7 +523,6 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
let formParams = new URLSearchParams();
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
@ -538,6 +534,11 @@ export class PetService {
let consumes: string[] = [
'application/x-www-form-urlencoded'
];
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
// to determine the Accept header
let produces: string[] = [
@ -555,20 +556,18 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
if (name !== undefined) {
formParams.set('name', <any>name);
formParams.set('name', name);
}
if (status !== undefined) {
formParams.set('status', <any>status);
formParams.set('status', status);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: formParams.toString(),
body: formParams,
search: queryParameters
});
@ -587,12 +586,11 @@ export class PetService {
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<Response> {
public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<Response> {
const path = this.basePath + `/pet/${petId}/uploadImage`;
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
let formParams = new URLSearchParams();
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
@ -604,6 +602,12 @@ export class PetService {
let consumes: string[] = [
'multipart/form-data'
];
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
useForm = canConsumeForm;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
// to determine the Accept header
let produces: string[] = [
@ -621,20 +625,18 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
if (additionalMetadata !== undefined) {
formParams.set('additionalMetadata', <any>additionalMetadata);
formParams.set('additionalMetadata', additionalMetadata);
}
if (file !== undefined) {
formParams.set('file', <any>file);
formParams.set('file', file);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: formParams.toString(),
body: formParams,
search: queryParameters
});

View File

@ -57,6 +57,20 @@ export class StoreService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
@ -131,15 +145,13 @@ export class StoreService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'orderId' is not null or undefined
if (orderId === null || orderId === undefined) {
throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -150,7 +162,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -176,9 +187,7 @@ export class StoreService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -194,7 +203,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -219,15 +227,13 @@ export class StoreService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'orderId' is not null or undefined
if (orderId === null || orderId === undefined) {
throw new Error('Required parameter orderId was null or undefined when calling getOrderById.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -238,7 +244,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -265,9 +270,7 @@ export class StoreService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -276,7 +279,6 @@ export class StoreService {
];
headers.set('Content-Type', 'application/json');

View File

@ -57,6 +57,20 @@ export class UserService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Create user
* This can only be done by the logged in user.
@ -199,9 +213,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -210,7 +222,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -241,9 +252,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -252,7 +261,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -283,9 +291,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -294,7 +300,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -323,15 +328,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling deleteUser.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -342,7 +345,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -367,15 +369,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling getUserByName.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -386,7 +386,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -412,6 +411,7 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (username !== undefined) {
queryParameters.set('username', <any>username);
}
@ -420,9 +420,6 @@ export class UserService {
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -433,7 +430,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -459,9 +455,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -472,7 +466,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -498,15 +491,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling updateUser.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -515,7 +506,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');

View File

@ -41,4 +41,4 @@ import { BASE_PATH } from './path-to-swagger-gen-service/index';
bootstrap(AppComponent, [
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
]);
```
```

View File

@ -57,6 +57,20 @@ export class PetService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Add a new pet to the store
*
@ -179,7 +193,7 @@ export class PetService {
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<{}> {
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<{}> {
return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
@ -203,11 +217,7 @@ export class PetService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/xml'
];
// to determine the Accept header
let produces: string[] = [
@ -225,7 +235,6 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/json');
@ -255,6 +264,7 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
@ -262,9 +272,6 @@ export class PetService {
headers.set('api_key', String(apiKey));
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -284,7 +291,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -309,14 +315,12 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (status !== undefined) {
queryParameters.set('status', <any>status);
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -336,7 +340,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -361,14 +364,12 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (tags !== undefined) {
queryParameters.set('tags', <any>tags);
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -388,7 +389,6 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -413,15 +413,13 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling getPetById.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -443,10 +441,14 @@ export class PetService {
{
headers.set('api_key', this.configuration.apiKey);
}
// authentication (api_key) required
if (this.configuration.apiKey)
{
headers.set('api_key', this.configuration.apiKey);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -473,11 +475,7 @@ export class PetService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/xml'
];
// to determine the Accept header
let produces: string[] = [
@ -495,7 +493,6 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/json');
@ -526,7 +523,6 @@ export class PetService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
let formParams = new URLSearchParams();
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
@ -538,6 +534,11 @@ export class PetService {
let consumes: string[] = [
'application/x-www-form-urlencoded'
];
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
// to determine the Accept header
let produces: string[] = [
@ -555,20 +556,18 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
if (name !== undefined) {
formParams.set('name', <any>name);
formParams.set('name', name);
}
if (status !== undefined) {
formParams.set('status', <any>status);
formParams.set('status', status);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: formParams.toString(),
body: formParams,
search: queryParameters
});
@ -587,12 +586,11 @@ export class PetService {
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<Response> {
public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<Response> {
const path = this.basePath + `/pet/${petId}/uploadImage`;
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
let formParams = new URLSearchParams();
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
@ -604,6 +602,12 @@ export class PetService {
let consumes: string[] = [
'multipart/form-data'
];
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
useForm = canConsumeForm;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
set(param: string, value: any): void;
};
// to determine the Accept header
let produces: string[] = [
@ -621,20 +625,18 @@ export class PetService {
headers.set('Authorization', 'Bearer ' + accessToken);
}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
if (additionalMetadata !== undefined) {
formParams.set('additionalMetadata', <any>additionalMetadata);
formParams.set('additionalMetadata', additionalMetadata);
}
if (file !== undefined) {
formParams.set('file', <any>file);
formParams.set('file', file);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: formParams.toString(),
body: formParams,
search: queryParameters
});

View File

@ -57,6 +57,20 @@ export class StoreService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
@ -131,15 +145,13 @@ export class StoreService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'orderId' is not null or undefined
if (orderId === null || orderId === undefined) {
throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -150,7 +162,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -176,9 +187,7 @@ export class StoreService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -194,7 +203,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -219,15 +227,13 @@ export class StoreService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'orderId' is not null or undefined
if (orderId === null || orderId === undefined) {
throw new Error('Required parameter orderId was null or undefined when calling getOrderById.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -238,7 +244,6 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -265,9 +270,7 @@ export class StoreService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -276,7 +279,6 @@ export class StoreService {
];
headers.set('Content-Type', 'application/json');

View File

@ -57,6 +57,20 @@ export class UserService {
return <T1&T2>objA;
}
/**
* @param consumes string[] mime-types
* @return true: consumes contains 'multipart/form-data', false: otherwise
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
if (form === consume) {
return true;
}
}
return false;
}
/**
* Create user
* This can only be done by the logged in user.
@ -199,9 +213,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -210,7 +222,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -241,9 +252,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -252,7 +261,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -283,9 +291,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -294,7 +300,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');
@ -323,15 +328,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling deleteUser.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -342,7 +345,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
@ -367,15 +369,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling getUserByName.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -386,7 +386,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -412,6 +411,7 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
if (username !== undefined) {
queryParameters.set('username', <any>username);
}
@ -420,9 +420,6 @@ export class UserService {
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -433,7 +430,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -459,9 +455,7 @@ export class UserService {
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -472,7 +466,6 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,
@ -498,15 +491,13 @@ export class UserService {
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'username' is not null or undefined
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling updateUser.');
}
// to determine the Content-Type header
let consumes: string[] = [
];
// to determine the Accept header
let produces: string[] = [
@ -515,7 +506,6 @@ export class UserService {
];
headers.set('Content-Type', 'application/json');