openapi-typescript-fetch icon indicating copy to clipboard operation
openapi-typescript-fetch copied to clipboard

How to provide request body?

Open JanCizmar opened this issue 2 years ago • 4 comments

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

JanCizmar avatar May 18 '22 12:05 JanCizmar

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

ajaishankar avatar May 18 '22 22:05 ajaishankar

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.

JanCizmar avatar May 19 '22 06:05 JanCizmar

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 ?

nilsmehlhorn avatar Aug 29 '22 13:08 nilsmehlhorn

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

igor-q-bio avatar Feb 01 '23 05:02 igor-q-bio