Skip to content

Any way to integrate Hono-OpenAPI with JStack? #81

Description

@Blankeos

https://hono.dev/examples/hono-openapi

I tried:

export contst postRouter = j.router({
  recent: publicProcedure
    .use(
      j.fromHono(
        describeRoute({
          description: "Awesome stuff",
          responses: {
            200: {
              description: "Successful response",
            },
          },
        }),
      ),
    )
    .query(({ c }) => {
      return c.superjson(posts.at(-1) ?? null);
    }),
// ...

and

const app = j.router();

app
  .get(
    "/api/docs/json",
    openAPISpecs(app, {
      documentation: {
        info: {
          title: "Hono API",
          version: "1.0.0",
          description: "JStack API",
        },
        servers: [
          { url: "http://localhost:3000", description: "Local Server" },
        ],
      },
    }),
  )
  .get(
    "/api/docs",
    Scalar((c) => {
      return {
        url: "/doc",
      };
    }),
  )
  .basePath("/api")
  .use(j.defaults.cors)
  .onError(j.defaults.errorHandler);

import { postRouter } from "./routers/post-router";

/**
 * This is the main router for your server.
 * All routers in /server/routers should be added here manually.
 */
const appRouter = j.mergeRouters(app, {
  post: postRouter,
});
export type AppRouter = typeof appRouter;

export default app;

I was really hoping it would work lol. Would be cool if Jstack supported it natively though. I'm seeing a usecase to have OpenAPI so maybe it's possible to generate a typesafe client on other languages (i.e. Dart/Flutter)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions