elysiajs / elysia-swagger

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

"Failed to load API definition." #6

Closed Northernside closed 1 year ago

Northernside commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

image
Northernside commented 1 year ago

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

image
igorrake commented 1 year ago

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 commented 1 year ago

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