Open
Description
openapi-react-query version
0.5.0
Description
POST
request made with openapi-fetch
and openapi-react-query
is missing the content-type
header (server expects application/json
).
Reproduction
My POST
spec specifies the request as application/json
requestBody:
description: Prioritization to create
content:
application/json:
Which I see generates the expected types:
requestBody: {
content: {
"application/json": components["schemas"]["Prioritization"];
};
};
However, when I use the query:
import createFetchClient from "openapi-fetch";
import createClient from "openapi-react-query";
const fetchClient = createFetchClient<paths>({
baseUrl: "/",
fetch: (input, init: RequestInit = {}) => {
const headers: HeadersInit = {
...init.headers,
...getAuthHeader(),
};
return fetch(input, { ...init, headers });
},
});
const api = createClient(fetchClient);
// ...
const addMutation = api.useMutation("post", "/prioritizations", {
onSuccess: () => {
// ...
},
onError: () => {
// ...
}
});
The network request does not have the correct content-type
header:
POST /v1/prioritizations HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Authorization: Bearer <...>
Connection: keep-alive
Content-Length: 73
Host: wunderfolio:9005
Origin: http://localhost:8089/
Referer: http://localhost:8089/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Expected result
POST
request should have Content-Type: application/json
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)