nuxt-open-fetch
nuxt-open-fetch copied to clipboard
header property is required but headers property is used for sending headers
Environment
- Operating System: Windows_NT
- Node Version: v22.11.0
- Nuxt Version: 3.14.159
- CLI Version: 3.15.0
- Nitro Version: 2.10.4
- Package Manager: [email protected]
- Builder: -
- User Config: default
- Runtime Modules: [email protected]
- Build Modules: -
Reproduction
Client usage
useApiClient('/api/endpoint', {
method: 'GET',
header: { 'X-Header': 'value' },
mode: 'cors',
credentials: 'same-origin',
server: false
})
Open API schema:
{
"x-generator": "NSwag v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))",
"openapi": "3.0.0",
"info": {
"title": "Api",
"version": "1.0.0"
},
"servers": [
{
"url": "https://localhost:5071"
}
],
"paths": {
"/api/endpoint": {
"get": {
"tags": [
"Endpoint"
],
"operationId": "Endpoint_Operation",
"parameters": [
{
"name": "X-Header",
"x-originalName": "xheader",
"in": "header",
"required": true,
"description": "Header",
"schema": {
"type": "string"
}
}
],
}
}
}
}
Describe the bug
When generating the api client from an OpenAPI schema the header property is generated with the required headers. However when specifying the header option on the fetch function the header will not be send.
The correct property is headers. Specifying this property will send the header with fetch.
Generated Code:
Endpoint_Operation: {
parameters: {
query?: never;
header: {
/** @description Header */
"X-Header": string;
};
path?: never;
cookie?: never;
};
};
Expected Code:
Endpoint_Operation: {
parameters: {
query?: never;
headers: {
/** @description Header */
"X-Header": string;
};
path?: never;
cookie?: never;
};
};
Additional context
No response
Logs
No response
i'm getting the same exact problem. Header is typed but it works only if the key is headers thus triggering typescript errors
I'm getting the same issue. It looks like everything is working as expected, so I'd be surprised if anyone doesn't have it. https://swagger.io/docs/specification/v3_0/describing-parameters/#header-parameters. Can we merge that PR?
Same problem here. There is any provision when this gonna be fixed? Everything works just fine, just this bug is annoying.
Are you using newest nuxt-open-fetch version? #80 had been tested & merged, but maybe there was a regression
Yes. I've just updated to the latest version, but the bug persists.
+1 use[Client] works, but $[client] still has the same problem.
Can you please provide a reproduction?
Can you please provide a reproduction?
https://stackblitz.com/edit/nuxt-starter-3foeetw6