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

schema5.openapi is not a function #167

Open
svengau opened this issue Aug 16, 2024 · 0 comments
Open

schema5.openapi is not a function #167

svengau opened this issue Aug 16, 2024 · 0 comments

Comments

@svengau
Copy link

svengau commented Aug 16, 2024

I've got an error when trying to directly use zod schema, rather than types proposed by the lib (Num, Str, ..).

I've found 2 workarounds, so this issue is low priority (you can even close it if you want), but at least it's documented in case someone has the same issue.

Also, it works on the official openAPI cloudflare templates. I've tried to find the diff between this project and mine, but impossible to fix it on my project.

✘ [ERROR] TypeError: schema5.openapi is not a function
      at null.<anonymous>
  (file:///.../node_modules/.pnpm/@[email protected][email protected]/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs:995:54)
      at Array.map (<anonymous>)
      at OpenAPIGenerator.generateInlineParameters
  (file:///.../node_modules/.pnpm/@[email protected][email protected]/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs:970:58)
      at enhanceMissingParametersError.location

my code:

export class Converter extends OpenAPIRoute {
  schema = {
    summary: "Convert a document",
    request: {
      query: z.object({
        // url: Str({ description: "Url of the document to convert" }), <-- this works ! :)
        url: z.string().describe("url of the document to convert"), <-- this doesn't work ! :(
      }),
...

Environment

Node v20.10.0

package.json

"@cloudflare/itty-router-openapi": "^1.0.1",
"chanfana": "^2.0.2",
"hono": "^4.5.5",
"wrangler": "^3.72.0"

wrangler.toml

compatibility_date = "2024-08-15"
#compatibility_flags = ["nodejs_compat"]
node_compat = true

Workaround 1

Simply add the following before your zod schema

import { z } from "zod";
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
extendZodWithOpenApi(z);

Workaround 2

Use type provided by chanfana.

import { Bool, Enumeration, ..., Str } from "chanfana";
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