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 no longer works with Hono 4.3.0 #496

Closed
bruceharrison1984 opened this issue May 3, 2024 · 7 comments · Fixed by honojs/hono#2605
Closed

Zod-OpenAPI no longer works with Hono 4.3.0 #496

bruceharrison1984 opened this issue May 3, 2024 · 7 comments · Fixed by honojs/hono#2605

Comments

@bruceharrison1984
Copy link

After upgrading Hono to 4.3.0, OpenAPI no longer appears to match response types.

image

export const userRoutes = app.openapi(
  createRoute({
    method: 'get',
    path: '/',
    tags: ['user'],
    security: [{ Bearer: [] }],
    request: {
      query: z.object({ limit: z.number(), offset: z.number() }),
    },
    responses: {
      200: {
        content: {
          'application/json': {
            schema: z.array(selectSchema),
          },
        },
        description: 'list of user',
      },
    },
  }),
  async (c) => {
    const { limit, offset } = c.req.queries();
    const resource = await c.var.MY_REPOSITORY.user.getAll(
      Number.parseInt(limit[0]),
      Number.parseInt(offset[0])
    );
    return c.json(resource, 200);
  }
);

Downgrading Hono back to 4.2.5 fixes the types again:
image

@yusukebe
Copy link
Member

yusukebe commented May 4, 2024

@bruceharrison1984

Thanks! We have to fix this issue.

Hi @NamesMT, are you interested in this Zod OpenAPI? If so, please check this issue. But I will be able to take a look later.

@NamesMT
Copy link

NamesMT commented May 4, 2024

Seems to be since 8129a3a - (4 days ago) feat(rpc): Add status code to response type

Will try to see if I can fix it, I'm going for lunch now.

@NamesMT
Copy link

NamesMT commented May 4, 2024

Okay, so on 4.3.0 we have two types breaking on ToSchema:

  • Update from O is output to extends TypedResponse - 8129a3a
  • Update from I accepting Input['in'] to Input - ea4e998

Previously I thought ToSchema is only for internal use so I didn't think much about it, but if it is exposed for other libraries I think we should revert ToSchema and creates a new ToSchemaV2 for future uses to revert the breaking changes?

@NamesMT
Copy link

NamesMT commented May 4, 2024

I will try to make a fast hotfix first to introduce some compatibility with older version that we can quick release.
Then we can create an issue to discuss the matter above ^

@yusukebe
Copy link
Member

yusukebe commented May 4, 2024

@NamesMT

Okay, thanks!

@NamesMT
Copy link

NamesMT commented May 4, 2024

honojs/hono#2605 will solve this after merge
image

@yusukebe
Copy link
Member

yusukebe commented May 4, 2024

Hi @bruceharrison1984

Thanks to @NamesMT , this has been fixed with the new version 4.3.1. Try it.

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

Successfully merging a pull request may close this issue.

3 participants