-
Notifications
You must be signed in to change notification settings - Fork 100
Description
This might be related to issue #205 but I cannot really tell.
We have a Swagger file with an endpoint for uploading a file. Our previous service that we wrote manually worked fine. We would put the uploaded file into FormData
along with some other key/value pairs.
const files = this.invoiceFile?.files
const file = files[0]
const formData = new FormData()
formData.append('invoice', file, file.name)
const formGroupValue = this.benefitBoxFormGroup.value
const requestFields:BenefitRequestFields = {
otherKey: 'otherValue',
(...)
}
formData.append('requestFields', JSON.stringify(requestFields))
this.benefitsService.postBenefitRequest(formData as unknown as BenefitRequestFields)
(...)
// method from own service:
public postBenefitRequest(body: BenefitRequestFields): Observable<SpaProfessionalsApiResponse> {
return this.httpClient.post<GenericResponse>(`${this.baseUrl}/benefitrequest`, body)
}
When generating services with ng-swagger-gen
everything worked perfectly except the upload. It looked as though there was no request payload.
When inspecting the generated code l came upon this weird bit:
let __body: any = null;
__body = params.requestFields;
__body = params.invoice;
Although this would not explain the empty payload, it does simply overwrite __body
with the second param.
Here is an excerpt from the yaml file:
paths:
/benefits/benefitrequest:
post:
tags:
- Benefits
summary: creates a benefit request for a specific goal
operationId: postBenefitRequest
consumes:
- multipart/form-data
security:
- JwtBearerAuthentication: [ ]
parameters:
- name: requestFields
in: body
required: true
schema:
$ref: '#/definitions/BenefitRequestFields'
- name: invoice
in: body
required: true
schema:
$ref: '#/definitions/BenefitRequestInvoice'
From other issue responses I gather a lack of time for support, but I'll file the issue anyway for others.
I will try to fix it myself and create a PR if I succeed. It might take a while because for now we have a workaround to the old service for this endpoint (but we will have other uploads in the future).