ajaishankar / openapi-typescript-fetch

A typed fetch client for openapi-typescript
MIT License
233 stars 54 forks source link

How to provide request body? #31

Open JanCizmar opened 2 years ago

JanCizmar commented 2 years ago

I need to pass formdata for file upload to the request, but there is no documented way how to do that.

ajaishankar commented 2 years ago

@JanCizmar only json request body is supported. The main use of the library is for strongly typed request and response...

JanCizmar commented 2 years ago

The request is strongly typed:

Relevant part of paths interface

  addFiles_1: {
    parameters: {
      query: {
        ak?: string;
      };
    };
    responses: {
      /** OK */
      200: {
        content: {
          "*/*": components["schemas"]["ImportAddFilesResultModel"];
        };
      };
      /** Bad Request */
      400: {
        content: {
          "*/*": string;
        };
      };
      /** Not Found */
      404: {
        content: {
          "*/*": string;
        };
      };
    };
    requestBody: {
      content: {
        "multipart/form-data": {
          files: string[];
        };
      };
    };
  };

So the request body is strictly typed.

nilsmehlhorn commented 2 years ago

I'm also encountering this use case for endpoints that expect binary bodies. I think this would be achievable by not overriding the body that can be passed via RequesInit with JSON if it's already present. What do you think @ajaishankar ?

igor-q-bio commented 1 year ago

Is there any update on this issue and the PR #50?

markmiller21 commented 2 days ago

Any movement on this? We're hacking around this bug at the moment (using a fetch as a post request). I would prefer to not switch architecture away from this but I can't tell soundly tell my team to continue in footsteps