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

Cannot read properties of undefined (reading 'uid') error! #177

Open
0xrasla opened this issue Dec 12, 2024 · 6 comments
Open

Cannot read properties of undefined (reading 'uid') error! #177

0xrasla opened this issue Dec 12, 2024 · 6 comments

Comments

@0xrasla
Copy link

0xrasla commented Dec 12, 2024

Hi, I'm experiencing a sudden and puzzling bug in my Swagger API project. Upon attempting to open the project today, I'm consistently encountering the following error across all endpoints:

"TypeError: Cannot read properties of undefined (reading 'uid')"

I've tried updating my package.json to utilize the latest version of @elysiajs/swagger (^1.1.6), but unfortunately, the issue persists.

Any guidance or support would be greatly appreciated.

image

image

@0xrasla
Copy link
Author

0xrasla commented Dec 12, 2024

I found a solution online! Adding the following inside the documentation resolves the issue:

servers: [
  {
    url: "/",
  },
],

It worked perfectly!

image

@raul-mg
Copy link

raul-mg commented Dec 12, 2024

I found a solution online! Adding the following inside the documentation resolves the issue:

servers: [
  {
    url: "/",
  },
],

It worked perfectly!

image

Can you extend your solution, starting what file you touch?

@0xrasla
Copy link
Author

0xrasla commented Dec 12, 2024

Sure! @raul-mg To extend the solution, you need to modify your main file where the Elysia app is initialized. Here’s how the implementation looks:

import { Elysia } from "elysia";

const app = new Elysia();

app.use(
  swagger({
    path: "/docs",
    exclude: ["/docs", "/docs/json"],
    theme: "dark",
    documentation: {
      servers: [
        {
          url: "/",
        },
      ],
      info: {
        title: "****",
        version: "1.0.0",
      },
      components: {
        securitySchemes: {
          bearerAuth: {
            scheme: "bearer",
            type: "http",
            bearerFormat: "JWT",
          },
        },
      },
    },
  })
);

Simply include this in your main file, and it should work perfectly!

@raul-mg
Copy link

raul-mg commented Dec 12, 2024

Sure! @raul-mg To extend the solution, you need to modify your main file where the Elysia app is initialized. Here’s how the implementation looks:
...

Simply include this in your main file, and it should work perfectly!

Excelent, just need documentation element and works, thanks

@Davispc10
Copy link

For this fix, I think just update the dependency @scalar/[email protected] to @scalar/[email protected].

@cholasimmons
Copy link

There was a time swagger didn't work due to some conflict with elysia-helmet, adding the following code fixed it, but I'm guessing some fix is causing [email protected] not to work anymore, because I've tried the fixes in this thread and Swagger went from showing "reading 'uid'" error, to just displaying a blank page.

.use(swagger({ autoDarkMode: true, documentation: {
        servers: [
          {
            url: "/"
          }
        ]
    } }))
    
    .use(helmet({
        contentSecurityPolicy: {
          useDefaults: true,
          directives: {
            "script-src": ["'self'", "https://cdn.jsdelivr.net/"],
          },
        }
      }))
    ```

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

4 participants