astahmer / typed-openapi

Generate a headless Typescript API client from an OpenAPI spec
https://typed-openapi-web.vercel.app/
191 stars 23 forks source link

Cookie parameter support #46

Open folklorelabs opened 2 months ago

folklorelabs commented 2 months ago

Hi -- it appears that this library currently only supports the following parameter types: query, path, header, and body based on what I'm seeing in the source code. Was it an intentional decision to not include cookie parameters? If not would it be possible to add support?

Here's an example for reference.

Swagger doc OpenAPI example endpoint:

{
  ...
  "/v1/testUserData/{locale}": {
    "get": {
      "tags": [
        "test-controller"
      ],
      "summary": "A summary of the test user endpoint",
      "description": "A description of the test user endpoint.",
      "operationId": "getTestUserData",
      "parameters": [
        {
          "name": "AUTH_TOKEN",
          "in": "cookie",
          "description": "Auth Cookie",
          "content": {
            "*/*": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        {
          "name": "locale",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "responses": {
        "200": {
          "description": "Success",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TestResponse"
              }
            }
          }
        }
      }
    }
  },
  ...
}
...

typed-openapi output based on the Swagger doc OpenAPI example above:

...
export type get_GetTestUserData = typeof get_GetTestUserData;
export const get_GetTestUserData = {
  method: z.literal("GET"),
  path: z.literal("/v1/testUserData/{locale}"),
  parameters: z.object({
    path: z.object({
      locale: z.string(),
    }),
  }),
  response: TestResponse,
};
...

As you can see it is stripping out the AUTH_TOKEN parameter.

astahmer commented 2 months ago

I didnt need it when I made this lib, I think it makes sense to add it, feel free to make a PR