cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
275 stars 37 forks source link

Doc pages breaking with Zod's bigint type #107

Open juliangehring opened 7 months ago

juliangehring commented 7 months ago

Using the bigint type of Zod seems to be breaking the /docs and redocs pages. A simple example based on the user guide, modified to use Zod's bigint instead of the normal Int:

import { OpenAPIRouter, OpenAPIRoute, Path, Int } from '@cloudflare/itty-router-openapi';
import { z } from 'zod'

export class ToDoFetch extends OpenAPIRoute {
    static schema = {
        parameters: {
            todoId: Path(z.coerce.bigint().nonnegative(), { // <-- using `bigint` here
                description: 'ToDo ID',
            }),
        },
    }

    async handle(
        request: Request,
        env: any,
        context: any,
        data: any
    ) {
        const { todoId } = data.params
        return new Response(todoId);
    }
}

const router = OpenAPIRouter()
router.get('/todos/:todoId', ToDoFetch)

export default {
    fetch: router.handle,
}

The docs page then throws: "Failed to load API definition. Fetch error response status is 500 /openapi.json" The redocs page is stuck in "Loading..."

When using the standard Int type instead, the doc pages load normally.