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

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

Open
wizofaus opened this issue Aug 4, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@wizofaus
Copy link
Contributor

wizofaus commented Aug 4, 2020

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
Copy link
Owner

Manweill commented Aug 4, 2020

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

@wizofaus
Copy link
Contributor Author

wizofaus commented Aug 4, 2020

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

@Manweill Manweill added the not active Close up for a long time is not active Issue label May 26, 2022
@Manweill Manweill closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2022
@wizofaus
Copy link
Contributor Author

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 Manweill reopened this May 26, 2022
@Manweill Manweill added enhancement New feature or request and removed not active Close up for a long time is not active Issue labels May 26, 2022
@Manweill
Copy link
Owner

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

@wizofaus
Copy link
Contributor Author

wizofaus commented May 26, 2022

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
Copy link
Owner

look forward to you submit full example

@fairking
Copy link
Collaborator

@wizofaus please feel free to join the discussion: #180

@fairking
Copy link
Collaborator

@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
Copy link
Contributor Author

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.

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

No branches or pull requests

3 participants