elysiajs / elysia-swagger

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

`scalarConfig.spec.url` is resolved incorrectly when the `path` option contains a subdirectory. #97

Open dtinth opened 10 months ago

dtinth commented 10 months ago

The changes introduced in #59 breaks in the case where swagger is mounted with path in the subdirectory.

const app = new Elysia()
  .use(
    swagger({
      path: "/services/docs",
    })
  )
  .get("/services/hello", () => ({ ok: true }));

When going to /services/docs, I get a blank page. This is because Scalar tries to load the data from /services/services/docs/json.

image

Current workaround is to manually override the scalarConfig

const app = new Elysia()
  .use(
    swagger({
      path: "/services/docs",
      scalarConfig: {
        spec: { url: "/services/docs/json" },
      },
    })
  )
  .get("/services/hello", () => ({ ok: true }));
DeluxeOwl commented 7 months ago

I also have this problem

recanman commented 4 months ago

this patch will fix it:

diff --git a/dist/index.mjs b/dist/index.mjs
index 10f8a7ca51e5ba7cf3e042e7a51a4140d3aae0d5..7b82200f3b393dbe3f27e84252fdc66875617c8a 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -577,7 +577,7 @@ var swagger = async ({
     version: "0.0.0",
     ...documentation.info
   };
-  const relativePath = path2.startsWith("/") ? path2.slice(1) : path2;
+  const relativePath = path2;
   const app = new Elysia({ name: "@elysiajs/swagger" });
   app.get(path2, function documentation2() {
     const combinedSwaggerOptions = {