elysiajs / elysia-swagger

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

fix: don't use relative paths #127

Open recanman opened 3 weeks ago

recanman commented 3 weeks ago

When setting a custom path for documentation (e.g /api/docs), Scalar requests the OpenAPI specification using the wrong path (as it is relative).

marclave commented 2 weeks ago

@recanman seems like we have some builds failing :) https://github.com/elysiajs/elysia-swagger/actions/runs/9555166692/job/26390291285?pr=127

recanman commented 2 weeks ago

Must've been asleep when making this PR, #11 was vastly outdated and I was attempting to fix a previous issue I had with this package.

I've been using this patch for getting custom paths to work:

diff --git a/node_modules/@elysiajs/swagger/dist/index.js b/node_modules/@elysiajs/swagger/dist/index.js
index 3863b14..7519681 100644
--- a/node_modules/@elysiajs/swagger/dist/index.js
+++ b/node_modules/@elysiajs/swagger/dist/index.js
@@ -31,7 +31,7 @@ export const swagger = ({ provider = 'scalar', scalarVersion = 'latest', scalarC
         version: '0.0.0',
         ...documentation.info
     };
-    const relativePath = path.startsWith('/') ? path.slice(1) : path;
+    const relativePath = path;
     app.get(path, () => {
         const combinedSwaggerOptions = {
             url: `${relativePath}/json`,