Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zod-openapi] wrong path in hono/client ? #528

Open
labordem opened this issue May 16, 2024 · 0 comments
Open

[zod-openapi] wrong path in hono/client ? #528

labordem opened this issue May 16, 2024 · 0 comments

Comments

@labordem
Copy link

Hello,

First of all, thank you for developing this exceptional library, it's a pleasure to work with!

However, I'm having a problem integrating hono/client, perhaps I'm missing something?

With new Hono() rpc works :

// main.tsx

const hono = new Hono().get(
  '/api/v1/users/:id',
  validator('param', (v) => z.object({ id: z.string().min(3) }).parse(v)),
  (c) => {
    const { id } = c.req.valid('param')
    return c.json({
      id,
      age: 20,
      name: 'Ultra-man',
    })
  },
)

export type HonoRpc = typeof hono

capture

With new OpenAPIHono() rpc path is incorrect (it take only first part) :

// main.tsx

const openapiHono = new OpenAPIHono().openapi(
  {
    method: 'get',
    path: '/api/v1/users/{id}',
    request: {
      params: z.object({
        id: z
          .string()
          .min(3)
          .openapi({
            param: {
              name: 'id',
              in: 'path',
            },
            example: '1212121',
          }),
      }),
    },
    responses: {
      200: {
        content: {
          'application/json': {
            schema: z
              .object({
                id: z.string().openapi({
                  example: '123',
                }),
                name: z.string().openapi({
                  example: 'John Doe',
                }),
                age: z.number().openapi({
                  example: 42,
                }),
              })
              .openapi('User'),
          },
        },
        description: 'Retrieve the user',
      },
    },
  },
  (c) => {
    const { id } = c.req.valid('param')
    return c.json({
      id,
      age: 20,
      name: 'Ultra-man',
    })
  },
)

export type OpenapiHonoRpc = typeof openapiHono

capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant