adonis-autoswagger icon indicating copy to clipboard operation
adonis-autoswagger copied to clipboard

Shown description is the response body description

Open Clement-Z4RM opened this issue 7 months ago • 7 comments

Hello, thank you for your work and this tool.

Description

I tried to add swagger comments on one of my controllers' routes, but the description shown is a wrong one. With this controller:

import Cible from "#models/cible";

export default class CiblesController {
    /**
     * @index
     * @summary Get the cibles list
     * @description Lorem ipsum dolor sit amet
     * @responseBody 200 - <Cible[]> - The cibles list
     * @responseBody 401 - <Errors> - Unauthorized access
     */
    async index() {
        return Cible.query().orderBy("id", "asc");
    }
}

the description shown on the Swagger UI (and even in the JSON) is "The cibles list" - which is the status 200 response body description -, instead of "Lorem ipsum dolor sit amet": Image

Expected behaviour

The route's description should be "Lorem ipsum dolor sit amet", like in this following screen (edited with Chrome DevTools): Image

Environment information

Versions

  • Node.js: 22.15.0 (LTS)
  • AdonisJS: 6.17.2
  • AutoSwagger: 3.72.0

Clement-Z4RM avatar Apr 24 '25 07:04 Clement-Z4RM

The description should come after the status

ad-on-is avatar Apr 24 '25 07:04 ad-on-is

I don't really understand what do you mean?

With another controller (authentication), it works well:

import type { HttpContext } from "@adonisjs/core/http";

export default class AuthController {
    /**
     * @logout
     * @summary Déconnexion d'un utilisateur
     * @description Cette méthode permet à un utilisateur de se déconnecter. Si son jeton d'accès est valide, il sera invalidé et l'utilisateur sera déconnecté.
     * @responseBody 200 - {} - Utilisateur déconnecté
     * @responseBody 401 - <Errors> - Accès non autorisé
     */
    async logout({ auth }: HttpContext) {
        await auth.use("api").invalidateToken();
    }
}

The @description is displayed under the title, not the response body description: Image

Clement-Z4RM avatar Apr 24 '25 08:04 Clement-Z4RM

Ohhg.. sorry... I thought the description had to be right after the status... sorry, my bad for the confusion

ad-on-is avatar Apr 24 '25 10:04 ad-on-is

Hello,

there’s a small bug: you need to double the space between statut and just before the dash in return, which should result in:

@responseBody 200  - <Cible[]> - The cibles list

addamai avatar Apr 27 '25 22:04 addamai

Hello, yes it worked, thank you for the work-around. Hopping it'll be fixed. However, the status 200 appears after the others, like if it was considered as "200 ", so Swagger doesn't know it. Image

Clement-Z4RM avatar Apr 28 '25 07:04 Clement-Z4RM

Hello, Normally, it follows the order of the comments: if you put it first, it will appear first; if you put it last, it will appear last. Check your console to see if there is any Swagger error.

addamai avatar Apr 28 '25 18:04 addamai

Hello, with this code:

import Cible from "#models/cible";

export default class CiblesController {
    /**
     * @index
     * @summary Get the cibles list
     * @description Lorem ipsum
     * @responseBody 200  - <Cible[]> - The cibles list
     * @responseBody 401 - <Errors> - Unauthorized access
     */
    index() {
        return Cible.query().orderBy("id", "asc");
    }
}

The order is bad: Image (No error in the console)

Clement-Z4RM avatar Apr 29 '25 09:04 Clement-Z4RM

Hi @Clement-Z4RM , I've published a new package to integrate Swagger/OpenAPI into your AdonisJS project easily.

More details: https://github.com/DreamsHive/open-swagger

DeVoresyah avatar Sep 19 '25 08:09 DeVoresyah