ad-on-is/adonis-autoswagger

Error on accessing localhost:3333/swagger

Opened this issue · 5 comments

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",

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

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?

#98 (comment)

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

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.

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. Julien-R44/hot-hook#9