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

OpenAPIHono not correctly inferring types from responses when using variables as keys #780

Open
kmallari opened this issue Oct 13, 2024 · 0 comments

Comments

@kmallari
Copy link

Actual Result

If I have a route like this:

import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"
import { StatusCodes } from "http-status-codes"

export const healthCheck = new OpenAPIHono<{ Variables: ContextVariables }>().openapi(
  createRoute({
    method: "get",
    path: "/health",
    tags: ["Health"],
    summary: "App health check",
    request: {},
    responses: {
      [StatusCodes.OK]: {
        description: "Success",
        content: {
          "application/json": {
            schema: healthCheckSchema.openapi("HealthCheck", {
              example: {
                server: "healthy",
                db: "healthy",
              },
            }),
          },
        },
      },
      [StatusCodes.INTERNAL_SERVER_ERROR]: {
        description: "Server failure.",
      },
    },
  }),
...

The REST method for get will get inferred as never
image
even though StatusCodes.OK is equal to 200

If I change [StatusCodes.OK] and [StatusCodes.INTERNAL_SERVER_ERROR] to 200 and 500 respectively, the types are inferred correctly.

Request

Be able to infer the type correctly, as long as the key is a valid HTTP code. This results in the RPC not being useable since _rpc_.$get() errors out since $get is inferred as never

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