I use fastify with swagger and fastify-type-provider-zod
My code
export const dayjsDateSchema = z
.custom<Dayjs>((val: any) => dayjs(val).isValid() || val === null, {
params: { expected: 'Dayjs', received: z.string() },
})
schema: {
operationId: 'passkeyList',
tags: ['oauth'],
summary: 'Get current passkey list',
response: {
200: z.object({
code: z.int().min(0).max(500),
data: z.array(
z.object({
id: z.string(),
displayName: z.string(),
createAt: dayjsDateSchema,
loginAt: dayjsDateSchema,
}),
),
}),
},
},
And the openapi json
"responses": {
"200": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": 0,
"maximum": 500
},
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"displayName": {
"type": "string"
},
// this is empty
"createAt": {
},
"loginAt": {
}
},
"required": [
"id",
"displayName",
"createAt",
"loginAt"
],
"additionalProperties": false
}
}
},
"required": [
"code",
"data"
],
"additionalProperties": false
}
}
}
}
I use fastify with swagger and fastify-type-provider-zod
My code
And the openapi json