Assigning a singular `Security` schema to a `Middleware` leads to an error.
Closed this issue · 1 comments
RobinTail commented
Discussed in #803
Originally posted by McMerph February 8, 2023
I want to specify that a particular middleware uses JWT Bearer Authentication.
So, I added:
security: { type: "bearer", format: "JWT" }
to createMiddleware
.
Unfortunately it didn't work -(
Error is:
TypeError: methods[security.type] is not a function
at {{PROJECT_DIR}}/node_modules/express-zod-api/src/open-api-helpers.ts:801:69
at {{PROJECT_DIR}}/node_modules/express-zod-api/src/logical-container.ts:40:15
at Array.map (<anonymous>)
at mapLogicalContainer ({{PROJECT_DIR}}/node_modules/express-zod-api/src/logical-container.ts:37:28)
at depictSecurity ({{PROJECT_DIR}}/node_modules/express-zod-api/src/open-api-helpers.ts:800:29)
at onEndpoint ({{PROJECT_DIR}}/node_modules/express-zod-api/src/open-api.ts:120:25)
at {{PROJECT_DIR}}/node_modules/express-zod-api/src/routing-walker.ts:46:9
at Array.forEach (<anonymous>)
at {{PROJECT_DIR}}/node_modules/express-zod-api/src/routing-walker.ts:45:15
at Array.forEach (<anonymous>)
What am I doing wrong?
security: { type: "bearer" }
doesn't work either.
Actually
security: { or: [{ type: "bearer", format: "JWT" }] }
or
security: { and: [{ type: "bearer", format: "JWT" }] }
both work but https://editor.swagger.io/ reports structural errors in this case (screenshot provided).
Both the middleware and the endpoint have an empty input (input: z.object({})
) if that matters.
RobinTail commented
Fixed in v8.9.2 🚀