Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

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

Open wizofaus opened 4 years ago

wizofaus commented 4 years ago

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

Manweill commented 4 years ago

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

wizofaus commented 4 years ago

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 commented 2 years ago

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

Manweill commented 2 years ago

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

wizofaus commented 2 years ago

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)
    })
  }```
Manweill commented 2 years ago

look forward to you submit full example

fairking commented 11 months ago

@wizofaus please feel free to join the discussion: https://github.com/Manweill/swagger-axios-codegen/pull/180

fairking commented 11 months ago

@wizofaus There is a new release which should solve your issue with plain text: https://github.com/Manweill/swagger-axios-codegen/releases/tag/v0.16.0

Please feel free to test it and close this issue if you are happy.

wizofaus commented 9 months ago

Don't really see how it generates a client-stub that will actually support uploading the plain-text content, but I haven't tried TBH. Do plan to start using this tool again soon actually so will let you know.