nuxt-open-fetch icon indicating copy to clipboard operation
nuxt-open-fetch copied to clipboard

header property is required but headers property is used for sending headers

Open Weeb6279 opened this issue 11 months ago • 2 comments

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

Weeb6279 avatar Dec 11 '24 06:12 Weeb6279

i'm getting the same exact problem. Header is typed but it works only if the key is headers thus triggering typescript errors

emavitta avatar Dec 11 '24 20:12 emavitta

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?

zlotnika avatar Feb 26 '25 18:02 zlotnika

Same problem here. There is any provision when this gonna be fixed? Everything works just fine, just this bug is annoying.

luanhenzo avatar Jul 07 '25 18:07 luanhenzo

Are you using newest nuxt-open-fetch version? #80 had been tested & merged, but maybe there was a regression

Norbiros avatar Jul 07 '25 18:07 Norbiros

Yes. I've just updated to the latest version, but the bug persists.

luanhenzo avatar Jul 07 '25 20:07 luanhenzo

+1 use[Client] works, but $[client] still has the same problem.

mschadev avatar Aug 06 '25 05:08 mschadev

Can you please provide a reproduction?

Norbiros avatar Aug 06 '25 06:08 Norbiros

Can you please provide a reproduction?

https://stackblitz.com/edit/nuxt-starter-3foeetw6

mschadev avatar Aug 06 '25 12:08 mschadev