Skip to content

fetch client request body is undefined when content-type is text/plain #2553

@franworks

Description

@franworks

Description

Following the change introduced in #2406
The request body is not included in the request when the content type is text/plain.

The fetch client sdk outputs the following example:

export const postExample = <ThrowOnError extends boolean = false>(options: Options<postExampleData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<postExampleResponses, postExampleErrors, ThrowOnError>({
        bodySerializer: null,
        security: [
            {
                scheme: 'bearer',
                type: 'http'
            }
        ],
        url: '/example/path',
        ...options,
        headers: {
            'Content-Type': 'text/plain',
            ...options.headers
        }
    });
};

When using the sdk and calling postExample({ body: 'data as a string' }) where the endpoint is expecting a post body, the call will fail because there is no body.

Reproducible example or configuration

Example open api spec and sdk output provided

OpenAPI specification (optional)

/example/path:
  post:
  ...
  requestBody:
    required: true
    content:
      text/plain:
        schema:
          type: string
          title: Sample Title

System information (optional)

@hey-api/openapi-ts 0.80.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workingclientClient package relatedjavascriptPull requests that update Javascript code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions