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

Simplifying the Definition of Request and Response Bodies in application/json Format #726

Open
CodyTseng opened this issue Sep 5, 2024 · 0 comments

Comments

@CodyTseng
Copy link

When using @hono/zod-openapi, defining request bodies and responses for APIs that utilize the application/json format seems unnecessarily verbose. Currently, we have to explicitly specify the content type for every request body and response, which adds repetitive boilerplate code. For example:

createRoute({
  method: 'post',
  path: '/users',
  request: {
    body: {
      content: {
        'application/json': {
          schema: CreateUserSchema,
        },
      },
    },
  },
  responses: {
    200: {
      content: {
        'application/json': {
          schema: UserSchema,
        },
      },
      description: 'success',
    },
  },
});

It would be much more convenient if there were a default shorthand for application/json to streamline this process. Ideally, we could define routes in a simpler way, like this:

createRoute({
  method: 'post',
  path: '/users',
  request: {
    body: CreateUserSchema,
  },
  responses: {
    200: {
      content: UserSchema,
      description: 'success',
    },
  },
});

This would make the code cleaner and more maintainable by eliminating redundant definitions. I believe such a shorthand would greatly enhance the developer experience and make the library more user-friendly.

Thank you for considering this suggestion!

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