honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
464 stars 167 forks source link

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

Open vickyRathee opened 5 months ago

vickyRathee commented 5 months ago

partial() function not available in latest version 0.14.2?

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

image

yusukebe commented 5 months ago

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'
    })
  }
)
vickyRathee commented 5 months ago

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

I guess due to upstream.

vickyRathee commented 2 months ago

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

yusukebe commented 2 months ago

@vickyRathee

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