Skip to content

when use header and cookie, and use same name(param1), header always return never #1798

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

Closed
2 tasks
liangskyli opened this issue Aug 2, 2024 · 3 comments · Fixed by #1849
Closed
2 tasks
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@liangskyli
Copy link
Contributor

Description

when use header and cookie, and use same name(param1), header always return never

error error

header?: never;

Expected result

header: {
          /** @description param1 */
          param1: string;
        };
Name Version
openapi-typescript 7.2.0
Node.js 18
OS + version Windows 10

Reproduction

How can this be reproduced / when did the error occur?

use openapi-v3.json
schema data

{
  "openapi": "3.1.0",
  "info": {
    "title": "@liangskyli/routing-controllers-openapi",
    "license": {
      "name": "This file is auto generated by @liangskyli/routing-controllers-openapi, do not edit!"
    },
    "version": "0.7.2"
  },
  "tags": [
    {
      "name": "Test1",
      "description": ""
    }
  ],
  "paths": {
    "/root/v1/getQueryParamWithQueryParams/{path1}/{path2}": {
      "get": {
        "tags": ["Test1"],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "number",
                      "description": "接口返回code码字段"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Response1.63007440"
                    },
                    "msg": {
                      "type": "string",
                      "description": "接口返回信息字段"
                    }
                  },
                  "required": ["code", "data"]
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "param1",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "param1"
          },
          {
            "name": "param1",
            "in": "cookie",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "param1"
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "IParam2.eb9fbc4a": {
        "type": "object",
        "properties": {
          "param1": {
            "description": "param1",
            "type": "string"
          }
        },
        "required": ["param1"]
      },
      "Response1.63007440": {
        "type": "object",
        "properties": {
          "activityBases2": {
            "type": "string"
          }
        },
        "required": ["activityBases2"]
      }
    }
  }
}

const result = await openapiTS(schema, {});
const  resultString = `${astToString(result)}`;

** error result**

export interface paths {
  '/root/v1/getQueryParamWithQueryParams/{path1}/{path2}': {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    get: {
      parameters: {
        query?: never;
        header?: never;
        path?: never;
        cookie: {
          /** @description param1 */
          param1: string;
        };
      };
      requestBody?: never;
      responses: {
        /** @description Success */
        200: {
          headers: {
            [name: string]: unknown;
          };
          content: {
            'application/json': {
              /** @description 接口返回code码字段 */
              code: number;
              data: components['schemas']['Response1.63007440'];
              /** @description 接口返回信息字段 */
              msg?: string;
            };
          };
        };
      };
    };
    put?: never;
    post?: never;
    delete?: never;
    options?: never;
    head?: never;
    patch?: never;
    trace?: never;
  };
}
export type webhooks = Record<string, never>;
export interface components {
  schemas: {
    'IParam2.eb9fbc4a': {
      /** @description param1 */
      param1: string;
    };
    'Response1.63007440': {
      activityBases2: string;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;

Expected result

export interface paths {
  '/root/v1/getQueryParamWithQueryParams/{path1}/{path2}': {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    get: {
      parameters: {
        query?: never;
        header: {
          /** @description param1 */
          param1: string;
        };
        path?: never;
        cookie: {
          /** @description param1 */
          param1: string;
        };
      };
      requestBody?: never;
      responses: {
        /** @description Success */
        200: {
          headers: {
            [name: string]: unknown;
          };
          content: {
            'application/json': {
              /** @description 接口返回code码字段 */
              code: number;
              data: components['schemas']['Response1.63007440'];
              /** @description 接口返回信息字段 */
              msg?: string;
            };
          };
        };
      };
    };
    put?: never;
    post?: never;
    delete?: never;
    options?: never;
    head?: never;
    patch?: never;
    trace?: never;
  };
}
export type webhooks = Record<string, never>;
export interface components {
  schemas: {
    'IParam2.eb9fbc4a': {
      /** @description param1 */
      param1: string;
    };
    'Response1.63007440': {
      activityBases2: string;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;

(in case it’s not obvious)

Checklist

@liangskyli liangskyli added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Aug 2, 2024
@drwpow
Copy link
Contributor

drwpow commented Aug 14, 2024

Thanks for filing! I’m going to mark this as a duplicate of #1771. Would welcome suggestions there on how openapi-fetch should handle it. Cookies can be tricky!

@drwpow drwpow closed this as completed Aug 14, 2024
@liangskyli
Copy link
Contributor Author

liangskyli commented Aug 14, 2024 via email

@drwpow
Copy link
Contributor

drwpow commented Aug 14, 2024

Oh I see now; my mistake. The use of openapi-fetch threw me off.

I see now—it’s the conflict of the name param1 that’s likely causing it to get dropped.

PRs would be welcome for this! This should be a nice, easy bug to fix.

@drwpow drwpow reopened this Aug 14, 2024
@drwpow drwpow added PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants