Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Weeb6279 opened this issue Dec 11, 2024 · 1 comment · May be fixed by #80
Open

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

Weeb6279 opened this issue Dec 11, 2024 · 1 comment · May be fixed by #80

Comments

@Weeb6279
Copy link

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

@emavitta
Copy link

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

@emavitta emavitta linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants