middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Zod partial() function not available in the zod-openapi ?

Open vickyRathee opened this issue 1 year ago • 4 comments

partial() function not available in latest version 0.14.2?

https://zod.dev/?id=partial

image

vickyRathee avatar Jun 05 '24 06:06 vickyRathee

Hi @vickyRathee

partial() function not available in latest version 0.14.2?

Yes, it supports partial():

import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi'

const openapiHono = new OpenAPIHono().openapi(
  createRoute({
    method: 'get',
    path: '/users/1',
    responses: {
      200: {
        content: {
          'application/json': {
            schema: z
              .object({
                name: z.string().openapi({
                  example: 'John Doe'
                }),
                age: z.number().openapi({
                  example: 42
                })
              })
              .partial()
              .openapi('User')
          }
        },
        description: 'Retrieve the user'
      }
    }
  }),
  (c) => {
    return c.json({
      age: 20,
      name: 'Ultra-man'
    })
  }
)

yusukebe avatar Jun 09 '24 05:06 yusukebe

Yes, thanks. It's working, but not with refine().partial()

I guess due to upstream.

vickyRathee avatar Jun 09 '24 14:06 vickyRathee

@yusukebe Any suggestion, I can't use partial(), extend() etc when refine() is used.

vickyRathee avatar Aug 29 '24 05:08 vickyRathee

@vickyRathee

I think refine().partial() is wrong. It should be partial().refine(). The latter will work well.

yusukebe avatar Sep 10 '24 07:09 yusukebe