Skip to content

zod-openapo openapi spec generation fails for routes imported from outside of #946

Open
@platform-kit

Description

@platform-kit

Which middleware has the bug?

@hono/zod-openapi

What version of the middleware?

^0.18.3

What version of Hono are you using?

^0.2.1

What runtime/platform is your app running on? (with version if possible)

Node

What steps can reproduce the bug?

git clone https://github.com/platform-kit/hono-example repro

cd repro/min-reproduction/api && npm i && npm run dev;

Console should output something like:

02:30:47 0|app    | Mounting function # 1 of 3 /api/healthcheck
02:30:47 0|app    | /Users/user/htdocs/repro/min-reproduction/api/src/functions/healthcheck/healthcheck.ts
02:30:47 0|app    | Success.
02:30:47 0|app    | Mounting function # 2 of 3 /api/healthcheck
02:30:47 0|app    | /Users/user/htdocs/repro/min-reproduction/api/workspace/src/functions/healthcheck/healthcheck.ts
02:30:47 0|app    | Success.
02:30:47 0|app    | Mounting function # 3 of 3 /api/healthcheck
02:30:47 0|app    | /Users/user/htdocs/repro/min-reproduction/workspace/src/functions/healthcheck/healthcheck.ts
02:30:47 0|app    | Success.

What is the expected behavior?

I have split my app up into several child-apps so that I can load them programmatically.

The files in api/src/functions are correctly imported, routes are mounted/served, with working input validation from Zod.

They also show up in the Open API spec (at http://localhost:8000/api/openapi-spec.json) as well as in the Scalar GUI (http://localhost:8000/api/). As expected.

What is unexpected is that the files that are imported from paths api/workspace/src/functions and workspace/src/functions (sibling to /api/) DO NOT get registered in the Open API schema or in the Scalar GUI, yet the routes DO work, with Zod validation and everything.

http://localhost:8000/api/healthcheck1?text=world is the file from api/src/functions/healthcheck. It shows up in the schema / GUI, and shows correct Zod validation behavior.

http://localhost:8000/api/healthcheck2?text=world and http://localhost:8000/api/healthcheck3?text=world are the other two routes from the other import paths.

They function correctly, but do not show up in the schema.

I've also noticed that the 2nd one shows up when I run the code in my local terminal, but not when I run the code inside a devcontaniner. Not sure what the significance of that would be.

What do you see instead?

2 of 3 routes are missing from Open API schema.

Additional information

What gives? I am not sure how to debug this.

Is there some way of forcing the createRoute method from @hono/zod-openapi to output some kind of log about the success/failure of converting the Zod schema to openapi spec?

I'm at a loss as to how to move forward, since it is not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions