Closed
Description
🐛 Bug Report:
Describe the bug
When an Angular service is generated with a method that requires a multipart / formData the result is incorrect
Steps to Reproduce
Steps to reproduce the behavior:
1 - Given a definition like this:
post:
tags:
- Document
summary: Consente il salvataggio di un documento
description: Crea un nuovo documento collegato alla FK company_id. Vengono ritornate
tutte le info di dettaglio del documento
operationId: documentCreate
parameters:
- name: id
in: path
description: Identificativo impresa
required: true
schema:
$ref: '#/components/schemas/UUID'
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
format: binary
type: string
fileName:
type: string
name:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/DocumentDTO'
"401":
description: Not Authorized
"403":
description: Not Allowed
2 - Run the script:
3 - The Angular service generated is:
public documentCreate(id: string, file?: Blob, fileName?: string, name?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<DocumentDTO>;
public documentCreate(id: string, file?: Blob, fileName?: string, name?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<DocumentDTO>>;
public documentCreate(id: string, file?: Blob, fileName?: string, name?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<DocumentDTO>>;
public documentCreate(id: string, file?: Blob, fileName?: string, name?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling documentCreate.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (SecurityScheme) required
localVarCredential = this.configuration.lookupCredential('SecurityScheme');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
// to determine the Content-Type header
const consumes: string[] = [
'multipart/form-data'
];
const canConsumeForm = this.canConsumeForm(consumes);
let localVarFormParams: { append(param: string, value: any): any; };
let localVarUseForm = false;
let localVarConvertFormParamsToString = false;
if (localVarUseForm) {
localVarFormParams = new FormData();
} else {
localVarFormParams = new HttpParams({encoder: this.encoder});
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.post<DocumentDTO>(`${this.configuration.basePath}/v1/companies/${encodeURIComponent(String(id))}/documents`,
localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
Expected behavior
let localVarUseForm = true
let localVarConvertFormParamsToString = false
if (localVarUseForm) {
localVarFormParams = new FormData()
localVarFormParams.append('fileName', fileName)
localVarFormParams.append('file', file)
localVarFormParams.append('name', name)
} else {
localVarFormParams = new HttpParams({ encoder: this.encoder })
}
Operation System:
- OS: Window
- Version 10
Package System:
- Version 2.4.16
Additional context
- Angular 12
- Quarkus 2