Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload endpoint generates strange code #265

Open
Sjeiti opened this issue Jul 22, 2021 · 0 comments
Open

upload endpoint generates strange code #265

Sjeiti opened this issue Jul 22, 2021 · 0 comments

Comments

@Sjeiti
Copy link

Sjeiti commented Jul 22, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant