Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger 1.1.0 does NOT load anymore #133

Open
cholasimmons opened this issue Jul 21, 2024 · 13 comments
Open

Swagger 1.1.0 does NOT load anymore #133

cholasimmons opened this issue Jul 21, 2024 · 13 comments

Comments

@cholasimmons
Copy link

I recently updated Elysia to 1.1.3 and Swagger to 1.1.0,
Off the bat helmet() prevented Elysia from running, which was fixed by rolling Elysia back to v1.1.2.
Then I noticed Swagger doesn't load at all (in either versions of Elysia), but rolling it back to version v1.0.5 worked instantly

@marclave
Copy link
Collaborator

hi @cholasimmons whats the error youre seeing? im just looking into this now : )

@cholasimmons
Copy link
Author

cholasimmons commented Jul 21, 2024

There's no error at all, the browser screen is actually just throwing a response that it would normally throw when the route exists (but you're not permitted to view it), it's almost like swagger is not loading at all.
The minute I downgrade to 1.0.5 it works instantly.

The recent Elysia update 1.1.3 gave me some issues with helmet() so maybe the problem is coming from there? In the past I recall helmet used to prevent swagger from loading without a little "directives" patch.

If it helps @marclave , here's the repo I was using: cholasimmons/bun-elysia-modular_auth

@anthony-legalfly
Copy link

Can confirm, this doesn't work on Swagger 1.1.0, downgraded to 1.0.5 and worked out of the box again.

The /health checks works without a bearer token and the authenticated routes I have after these as well. The Swagger endpoints seems to get routed through the authentication because I get the Unauthorized error.

const app = new Elysia()
    .use(
        swagger( {
            documentation: {
                info: {
                    title: 'LegalFly\'s On Prem Server Documentation',
                    version: '1.0.0',
                },
            },
        } ),
    )
    .decorate( "healthController", new HealthController() )
    .get( "/health",
        async ( { healthController } ) => await healthController.checkHealth() )
    .use( bearer() )
    .derive( async ( { bearer } ) =>
    {
        if ( !bearer || bearer !== appConfig.secret ) {
            throw new Error( "Unauthorized" );
        }
    } )

@DaniumX
Copy link

DaniumX commented Aug 6, 2024

Can confirm, this doesn't work on Swagger 1.1.0, downgraded to 1.0.5 and worked out of the box again.

The /health checks works without a bearer token and the authenticated routes I have after these as well. The Swagger endpoints seems to get routed through the authentication because I get the Unauthorized error.

const app = new Elysia()
    .use(
        swagger( {
            documentation: {
                info: {
                    title: 'LegalFly\'s On Prem Server Documentation',
                    version: '1.0.0',
                },
            },
        } ),
    )
    .decorate( "healthController", new HealthController() )
    .get( "/health",
        async ( { healthController } ) => await healthController.checkHealth() )
    .use( bearer() )
    .derive( async ( { bearer } ) =>
    {
        if ( !bearer || bearer !== appConfig.secret ) {
            throw new Error( "Unauthorized" );
        }
    } )

Same here. Any solution?

@marclave
Copy link
Collaborator

marclave commented Aug 6, 2024

investigating today!

immediately im not sure whats up 🤔

@lomithrani
Copy link

I have an error on 1.1.0+ when starting my app , rolled back successfully to 1.05. I think this is probably related
Error when starting is : (plugin2 is swagger)

6793 |           if (plugin2 instanceof _Elysia) return this._use(plugin2);
6794 |           if (typeof plugin2.default === "function")
6795 |             return plugin2.default(this);
6796 |           if (plugin2.default instanceof _Elysia)
6797 |             return this._use(plugin2.default);
6798 |           throw new Error(
                       ^
error: Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.
      at [...]/node_modules/elysia/dist/cjs/index.js:6798:17

@assapir
Copy link

assapir commented Aug 27, 2024

Same problem here.

3218 |                                                  return plugin.default(this)
3219 | 
3220 |                                          if (plugin.default instanceof Elysia)
3221 |                                                  return this._use(plugin.default)
3222 | 
3223 |                                          throw new Error(
                   ^
error: Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.
      at /Users/assaf/code/work/sidedish/apps/api/node_modules/elysia/src/index.ts:3223:13

when using Swagger, the error disappears when commented out.

in package.json: "@elysiajs/swagger": "^1.0.5",
in lock file:

"@elysiajs/swagger@^1.0.5": 
  version "1.1.1"
  resolved "https://registry.npmjs.org/@elysiajs/swagger/-/swagger-1.1.1.tgz"
  integrity sha512-fsg5IZaNbgN2kWqSRUntSMqg386cmFbT7IrYm2gH1P9e34ZD2wuKhRCu521+T924UunwIHP2+tj6CoFL4FrsxQ==
  dependencies: 
    lodash.clonedeep "^4.5.0"
    openapi-types "^12.1.3

Confirmed to work when pinning the version to 1.0.5

@tanishqmanuja
Copy link

tanishqmanuja commented Aug 30, 2024

Same here, 404 NOT_FOUND

Edit:
It was a malfunctioning middleware called after swagger.

For anyone else facing this issue .. try to move the swagger plugin to the topmost level and see if it works.

@cham11ng
Copy link

cham11ng commented Sep 2, 2024

For anyone else facing this issue .. try to move the swagger plugin to the topmost level and see if it works.

Tried moving it, still the same. I am facing same issue as @DaniumX - #133 (comment).

 "@elysiajs/jwt": "^1.1.0",
 "@elysiajs/swagger": "^1.1.1",
 "elysia": "^1.1.8",

@DaniumX
Copy link

DaniumX commented Sep 8, 2024

Another problem is that Swagger breaks completely if you use .model().

@linmeii
Copy link

linmeii commented Sep 17, 2024

Can confirm, swagger is breaking while using .model()
Zrzut ekranu 2024-09-17 o 23 34 43
When entering /swagger page im getting error on /swagger/json that can't find some model in my codebase.
It prevents to generate any routes with tags

@codecorsair
Copy link

I get the same issue with the "Invalid plugin type." error with version 1.1.1 of @elisiajs/swagger within a SvelteKit server page. Changing @elisiajs/swagger to version 1.0.5 does resolve the error within SvelteKit.

@ViliamKopecky
Copy link

Still not working with @elysiajs/swagger 1.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests