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

Validators are not included in Swagger schemas when running in HMR mode (node ace serve --hmr) #151

Open
Leoglme opened this issue Feb 9, 2025 · 0 comments

Comments

@Leoglme
Copy link

Leoglme commented Feb 9, 2025

Description:
When using adonis-autoswagger in an AdonisJS v6 project, validators (app/validators/*.ts) are not included in the generated Swagger schemas when running the server in HMR mode (node ace serve --hmr). However, models (app/models/*.ts) are correctly generated in both watch and HMR modes.

Steps to Reproduce:

  1. Install adonis-autoswagger in an AdonisJS 6 project.

  2. Add a validator file, for example:

    // app/validators/post.ts
    import vine from '@vinejs/vine'
    
    export const createPostValidator = vine.compile(
      vine.object({
        username: vine.string().trim().minLength(6),
      })
    )
  3. Reference the validator in a controller:

    import { createPostValidator } from '#validators/post'
    
    export default class UsersController {
      /**
       * @tag User
       * @summary Create a new user
       * @requestBody <createPostValidator>
       * @responseBody 200 - {"message": "User created"}
       */
      public async postUser({ request, response }: HttpContext): Promise<void> {
        const payload = await createPostValidator.validate(request.all())
        response.json({ message: 'User created' })
      }
    }
  4. Run the following commands and check the Swagger UI (http://localhost:3333/docs):

    • node ace docs:generate (Schemas are correctly generated)
    • node ace serve --watch (Schemas are correctly generated)
    • node ace serve --hmr (Validators are missing from Swagger schemas, but models still appear)

Expected Behavior:

Validators (app/validators/*.ts) should be included in Swagger schemas when running the server in HMR mode (node ace serve --hmr), just like they are when using node ace serve --watch.

Actual Behavior:

  • Models (app/models/*.ts) are detected and included in schemas correctly.
  • Validators (app/validators/*.ts) are missing in HMR mode but work fine in Watch mode.
  • Swagger UI (http://localhost:3333/docs) throws the following error in HMR mode:
    Errors
    Resolver error at paths./user.post.requestBody.content.application/json.schema.$ref
    Could not resolve reference: Could not resolve pointer: /components/schemas/createPostValidator does not exist in document
    
  • Debug logs show that validators are found but not processed:
    Found model files [
      'C:\\Users\\leogu\\Desktop\\Projects\\hello-world\\app/models/user.ts'
    ]
    Found interfaces files []
    Found validator files [
      'C:\\Users\\leogu\\Desktop\\Projects\\hello-world\\app/validators/post.ts'
    ]
    **You are probably using 'node ace serve --hmr', which is not supported yet. Use 'node ace serve --watch' instead.** 
    Node C:\Users\leogu\Desktop\Projects\hello-world\app\validators\post.ts does not exist
    

Environment:

  • AdonisJS Version: 6.17.1
  • adonis-autoswagger Version: 3.64.0
  • Node.js Version: 22.13.1
  • Operating System: Windows 11 WSL 2
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

1 participant