swagger-axios-codegen icon indicating copy to clipboard operation
swagger-axios-codegen copied to clipboard

Code generated for APIs requiring text/plain (etc.) as request content type not useful

Open wizofaus opened this issue 3 years ago • 9 comments

We have a couple of APIs for uploading documents, that in our swagger look like, e.g.:

 "/v1/validateFile": {
      "post": {
        "operationId": "validateFile",
        "consumes": [
          "text/plain"
        ],
        "produces": [
          "application/json"
        ],

But the function generated by swagger-axios-codegen has

     let data = null

      configs.data = data
      axios(configs, resolve, reject)

i.e., there's no way to pass in the actual contents to upload to the API!

Again, I could look at contributing a fix, but is this something you'd come across before?

We also have some APIs that require application/octet-stream as the input (binary file uploads).

Thanks!

Dylan

wizofaus avatar Aug 04 '20 05:08 wizofaus

Only Application/JSON and Multipart/form-Data are implemented

Manweill avatar Aug 04 '20 06:08 Manweill

Are you happy for me to contribute a fix? Intention would be to add an extra string parameter 'content' to the client method (would need to check for an existing such param obviously).

wizofaus avatar Aug 04 '20 23:08 wizofaus

This is still something I believe swagger codegen would benefit from, and I was happy to contribute an implementation, but I'd hoped for confirmation that you thought my proposal made sense...

wizofaus avatar May 26 '22 03:05 wizofaus

so, what your mean? and codegen result like ?do you provide an example?

Manweill avatar May 26 '22 06:05 Manweill

Completed untested, but perhaps something like

  static validateFile(
    content?: string,
    options: IRequestOptions = {},
  ): Promise<ValidateFileResponse> {
    return new Promise((resolve, reject) => {
      let url = '/v1/validateFile'

      const configs: IRequestConfig = getConfigs('post', 'text/plain', url, options)
      configs.data = content
      axios(configs, resolve, reject)
    })
  }```

wizofaus avatar May 26 '22 07:05 wizofaus

look forward to you submit full example

Manweill avatar May 27 '22 06:05 Manweill