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

c.html() with zop openAPI gives error #958

Open
xkeshav opened this issue Feb 4, 2025 · 0 comments
Open

c.html() with zop openAPI gives error #958

xkeshav opened this issue Feb 4, 2025 · 0 comments
Labels

Comments

@xkeshav
Copy link

xkeshav commented Feb 4, 2025

Which middleware has the bug?

@hono/zod-openapi

What version of the middleware?

0.18.4

What version of Hono are you using?

4.6.20

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

Node.js

What steps can reproduce the bug?

we have multiple API and handler all are working fine but only 1 APi failing which respons eis in txt/html and here is the code for that

src/components/Home.tsx

import { Layout } from "@/components/Layout";

interface SiteData {
  title: string;
  description: string;
  children?: any;
}

export function Home(props: { siteData: SiteData; name: string }) {
  return (
    <Layout { ...props.siteData }>
      <h1>
        Hello  { props.name }
      </h1>
    </Layout>
  );
}

src/common.handler.ts

import type { Context } from "hono";

import { Home } from "@/components/Home";

import type { AppRouterHandler } from "@/types/common";

export const basic: AppRouterHandler<any> = (c) => {
  const props = {
    name: "Hacker",
    siteData: {
      title: "Home Page",
      description: "Hono is cool!",
    },
  };
  return c.html(<Home { ...props } />);
};

common/common.routes.ts

import type { z } from "@hono/zod-openapi";

type ZodSchema = z.ZodUnion | z.AnyZodObject | z.ZodArray<z.AnyZodObject>;

function htmlContent<T extends ZodSchema>(schema: T, description: string) {
  return {
    content: {
      "text/html": {
        schema
      }
    },
    description
  };
}

export const basic = createRoute({
  path: "/",
  method: "get",
  tags,
  responses: {
   200: htmlContent(z.string(), "basic  routeIndex")
  }
});

sommon/common.index.ts

import { createRouter } from "@/libs/create-app";
import * as handlers from "@/routes/common/common.handlers";
import * as routes from "@/routes/common/common.routes";

const router = createRouter()
  .openapi(routes.basic, handlers.basic);

and here is configure-open-api.ts

import type { OpenAPIHono } from "@hono/zod-openapi";
import { apiReference } from "@scalar/hono-api-reference";

import type { AppBindings } from "@/middlewares";

import pkg from "../../package.json";

type AppOpenAPI = OpenAPIHono<AppBindings>;

export default function configureOpenAPI(app: AppOpenAPI) {
  app.doc("/doc", {
    openapi: "3.0.0",
    info: {
      version: pkg.version,
      title: "TZ Server",
      description: "API for managing project"
    }
  });

  app.get(
    "/reference",
    apiReference({
      pageTitle: "Project: API Reference",
      theme: "moon",
      layout: "modern",
      defaultHttpClient: {
        targetKey: "javascript",
        clientKey: "fetch"
      },
      spec: {
        url: "/doc"
      }
    })
  );

and when run and open localhost:3000/refrences and hit / using test run it gives error

The URL seems to be invalid

on bottom of the page that Inavlia URL; here is screenshot for the same.

Image

What is the expected behavior?

It should display the text/html page which opens on localhost:3000

What do you see instead?

gives error Invalid URL and hono stopped sometimes

Additional information

running on ubuntu 24.04

@xkeshav xkeshav added the triage label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant