elysiajs / elysia-swagger

A plugin for Elysia to auto-generate Swagger page
MIT License
74 stars 36 forks source link

incorrect work with type recursion #119

Open ilyhalight opened 2 months ago

ilyhalight commented 2 months ago

If we set the response type as an object containing recursion, an error occurs when opening the endpoint in swagger (and incorrect types are displayed in the example), while scalar stops working altogether.

Full code example:

import { Elysia, t } from "elysia";
import { swagger } from "@elysiajs/swagger";

const app = new Elysia()
  .use(
    swagger({
      provider: "swagger-ui", // scalar doesn't work bruh
      path: "/docs",
      documentation: {
        info: {
          title: "test",
          version: "1.0.0",
        },
        tags: [
          { name: "App", description: "General endpoints" },
          { name: "Users", description: "User endpoints" },
        ],
      },
    })
  )
  .get(
    "/test",
    () => {
      return {
        test: "321",
        part: {
          test: "32133",
        },
      };
    },
    {
      response: {
        200: t.Recursive((This) =>
          t.Object({
            test: t.String(),
            part: t.Optional(This),
          })
        ),
      },
    }
  )
  .listen({
    port: 3000,
    hostname: "0.0.0.0",
  });

console.log(
  `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);

изображение изображение