ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
129 stars 41 forks source link

Error on accessing localhost:3333/swagger #102

Open GilTRipper opened 5 months ago

GilTRipper commented 5 months ago

Here im using example from readme to access docs vida /docs route

/*
|--------------------------------------------------------------------------
| Routes file
|--------------------------------------------------------------------------
|
| The routes file is used for defining the HTTP routes.
|
*/

import '#routes/api'

import AutoSwagger from 'adonis-autoswagger'
import swagger from '#config/swagger'
import router from '@adonisjs/core/services/router'

// returns swagger in YAML
router.get('/swagger', async () => {
  // console.log(router.toJSON())
  return AutoSwagger.default.docs(router.toJSON(), swagger)
})

// Renders Swagger-UI and passes YAML-output of /swagger
router.get('/docs', async () => {
  return AutoSwagger.default.ui('/swagger', swagger)
  // return AutoSwagger.default.scalar("/swagger", swagger); to use Scalar instead
  // return AutoSwagger.default.rapidoc("/swagger", swagger); to use RapiDoc instead
})

but when i'm trying to reach localhost:3333/docs got this issue Node .../backend/app/validators/auth.ts does not exist

my validators/auth.ts

import vine from '@vinejs/vine'
import { ExtractSchemaType } from './types.js'

export const createAccountValidator = vine.compile(
  vine.object({
    username: vine.string().trim().minLength(5).maxLength(32),
    email: vine.string().email(),
    password: vine.string().minLength(8).maxLength(32),
  })
)

export const loginValidator = vine.compile(
  vine.object({
    username: vine.string(),
    password: vine.string(),
  })
)

export type CreateAccountData = ExtractSchemaType<typeof createAccountValidator>
export type LoginData = ExtractSchemaType<typeof loginValidator>

the strange is that when i'm using node ace docs:generate everything is fine

"adonis-autoswagger": "^3.47.0",

CostierLucas commented 5 months ago

I encountered the same error initially. However, it's peculiar because after sending a POST request from my client to the backend, the Swagger documentation was displayed correctly and the error disappeared. But when I restart my server, the error reappears

ad-on-is commented 5 months ago

I encountered the same error initially. However, it's peculiar because after sending a POST request from my client to the backend, the Swagger documentation was displayed correctly and the error disappeared. But when I restart my server, the error reappears

whuuuut?

could someone create a reproducable adonisjs project and upload it to github?

CostierLucas commented 5 months ago

https://github.com/ad-on-is/adonis-autoswagger/issues/98#issuecomment-2178209270

it's pretty much the same error, it says that the validator file doesn't exist when it already does

ad-on-is commented 5 months ago

I just found out! This is an issue with node ace serve --hmr Using node ace serve --watch however, works as expected. If someone knows how to solve it, I'd appreciate it.

ad-on-is commented 5 months ago

For now, I've added a warning message, so it's at least clear what's going on, until the issue is somehow fixed.

Edit: I contacted the developer of hot-hook, to see whether it's an upstream issue, or an issue with AutoSwagger. https://github.com/Julien-R44/hot-hook/issues/9