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

"Failed to load API definition." #6

Closed
Northernside opened this issue May 12, 2023 · 5 comments
Closed

"Failed to load API definition." #6

Northernside opened this issue May 12, 2023 · 5 comments

Comments

@Northernside
Copy link

When trying to access the swagger url, it greets me with the following error:
image
And then when going to the direct JSON endpoint it shows me this in the browser:

Object.entries requires that input parameter not be null or undefined

Though, this only happens when being on the experimental version from elysia. I need that version though, because of the other routing bug in latest 👀
I don't know if I should report it here or in the other repository.

Example Code:

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

export const app = new Elysia()
    .use(swagger({
        path: "/api/swagger",
        swagger: {
            info: {
                title: "e.bio API",
                version: "2.0.0-beta"
            }
        }
    }));

app.get("/api", () => {
    res.send("Hello World!");
});

Also, I don't know why, but the specified title and version aren't showing either within Swagger on elysia@latest since a few weeks.

@SaltyAom
Copy link
Member

Got it, Elysia experimental has an internal breaking change for handling schema which I haven't updated the swagger plugin to match the latest version yet.

Updating to @elysiajs/swagger: ^0.5.0-beta.0 should fix your problem.

@Northernside
Copy link
Author

Thank you, this resolved my issue :)
Though, the other one with the title and version isn't. Should I open another issue?
image

@Northernside
Copy link
Author

Oh, and also it seems like the scheme isn't loading?
image

@igorrake
Copy link

igorrake commented Aug 9, 2023

I assume I came a little bit too late but if you still need to solve this, @Northernside:

For the "info" object, you need to nest it under "documentation".

const app = new Elysia().use(
  swagger({
    documentation: {
      info: {
        title: "Elysia Documentation",
        version: "1.0.0",
        description: "Development docs.",
      },
      ..

For the schema, something like this:

app.get("/api", () => {
  res.send("Hello World!");
},{
  response: {
    200: {
      id: t.Number({
        description: "Unique identifier.",
        default: 666,
      }),
      name: t.String({
        description: "Name of mercenary.",
        default: "John Wick",
      }),
    },
  },
  detail: {
    summary: `Gets details of all available mercenaries.`,
    tags: ["Mercenaries"],
  },
});

@Northernside
Copy link
Author

Ohh sorry for the late response.
That's great, thank you! <3

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

3 participants