asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
997 stars 61 forks source link

Combine config.parameters with ones generated from config.request #164

Closed smowli closed 1 year ago

smowli commented 1 year ago

Hey 👋🏻. Currently when using registerPath method if both fields RouteConfig.parameters and RouteConfig.request are defined, parameters field is overwritten by the request field.

Would it be possible to combine these two fields?

I encountered this when i tried to do this 👇🏻 as cookies field is not currently present in the request object:

registry.registerPath({
      ...
      parameters: [
        {
          in: 'cookie',
          name: 'sessionCookie',
        },
      ],
      request: {
        query: z.object({
          id: z.string(),
        }),
      },
    });

which results in:

parameters: [
      {
        schema: { type: 'string' },
        required: true,
        name: 'id',
        in: 'query'
      }
]

instead of:

parameters: [
      { in: 'cookie', name: 'sessionCookie' },
      {
        schema: { type: 'string' },
        required: true,
        name: 'id',
        in: 'query'
      }
]
AGalabov commented 1 year ago

@vosmol thank you for your contribution. I've released v5.5.0 that supports this as well (even with the added support for cookies, it makes sense to have it as a manual approach if someone needs it)