Skip to content

Incorrect processing of requests with text/plain body #2382

@cyberbobs

Description

@cyberbobs

openapi-fetch version

0.14.0

Description

openapi-fetch doesn't cope well with methods accepting text/plain body. It ignores the compiled information about the body content and processes the passed arguments as application/json.

Reproduction

We have an OpenAPI schema with an endpoint that goes like this.

post:
  requestBody:
    required: true
    content:
      text/plain:
        schema:
          type: string

The compiler then processes it correctly:

"/api/my_method": {
  parameters: {
    query?: never;
    header?: never;
    path?: never;
    cookie?: never;
  };
  get?: never;
  put?: never;
  post: {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    requestBody: {
      content: {
          "text/plain": string;
      };
    };
  // ...
  }
}

But the request sent by browser has:

  • Content-Type: application/json header (that we could change manually passing the header ourselves)
  • The body parameter has string type but it is encoded with JSON.stringify before being sent.

Expected result

The request should be sent with a correct Content-Type and not be encoded as JSON value.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions