Skip to content

@elysia/openapi/gen fails to generate types for imported routers #249

@alimehasin

Description

@alimehasin

I’m using @elysia/openapi/gen to generate TypeScript types for my Elysia routes. It works fine when all routes are in a single file. However, when I split routes into multiple routers and import them using .use(), I get the following error:

Couldn't find generated declaration file
You can override with `overrideOutputPath` with one of the following:
- plugins/openapi.d.ts
- routes/posts.d.ts

Steps to reproduce

  1. Create a main router (app.ts) and a secondary router (posts.ts).
  2. In posts.ts:
import { Elysia } from "elysia";

interface Post {
  id: number;
  title: string;
  content: string;
}

const data: Post[] = [{ id: 1, title: "Post 1", content: "Content 1" }];

export const posts = new Elysia({ prefix: "/posts" }).get("/", () => {
  return data;
});
  1. In app.ts:
import { openapi } from "@elysiajs/openapi";
import { fromTypes } from "@elysiajs/openapi/gen";
import { Elysia } from "elysia";
import { posts } from "./routes/posts";

export const app = new Elysia()

  // Plugins
  .use(
    openapi({
      path: "/docs",
      references: fromTypes("src/server.ts"),
    }),
  )

  // Routes
  .use(posts);

app.listen(3000);

Expected Behavior

Types should be generated correctly for all routes, including imported routers.

Actual Behavior

gen fails with the “Couldn't find generated declaration file” error.

Notes

  • Works fine if all routes are in a single file.
  • Seems like the issue happens only if the imported routes has a type/interface in it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions