Skip to content

client-fetch does not body-serialize valid json values that are falsey #2589

@LinuCC

Description

@LinuCC

Description

Hi, thanks again for the great work on this lib!

Using client-fetch, falsey values passed in as body (such as 0, "", false) will not get serialized and subsequently the body will be empty.

I've added a PR #2590 .

Edit: Looks like it'll be fixed in #2564 .

Reproducible example or configuration

Taken a test in client-fetch from the PR:

  it('serializes an empty json string to a json-parseable body', async () => {
    const mockResponse = new Response(null, {
      status: 200,
    });

    const mockFetch: MockFetch = vi.fn().mockResolvedValue(mockResponse);

    const result = await client.request({
      body: '',
      fetch: mockFetch,
      method: 'PUT',
      url: '/test',
    });

    expect(await result.request.text()).toBe('""');
  });

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workingclientClient package related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions