PiotrFLEURY/nenuphar_cli

Error Command nenuphar gen

Closed this issue · 3 comments

I found error when using nenuphar gen command, it's someting not found allowed method.
evaluating path: \api\auth\login
No allowed methods found for \api\auth\login
Using default allowed methods: [options, get, head, post, put, patch, delete]
evaluating path: \api\auth\register
No allowed methods found for \api\auth\register
Using default allowed methods: [options, get, head, post, put, patch, delete]

This is my route login

import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
import 'package:travel_plan/controller/auth/auth_controller.dart';

Future<Response> onRequest(RequestContext context) async {
  return switch(context.request.method) {
    HttpMethod.post => AuthController.instance.login(context),
    _ => Future.value(Response(statusCode: HttpStatus.methodNotAllowed))
  };
}

This is my route register

import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
import 'package:travel_plan/controller/auth/auth_controller.dart';

Future<Response> onRequest(RequestContext context) async {
  return switch(context.request.method) {
    HttpMethod.post => AuthController.instance.register(context),
    _ => Future.value(Response(statusCode: HttpStatus.methodNotAllowed))
  };
}

Update:
I add comment section for Allow Method like this:

///
/// The /api/auth/login routes
///
/// @Allow(POST) - Allow only POST methods
///
/// @Header(User-Name) - The user name header
///
///
Future<Response> onRequest(RequestContext context) async {
  return switch(context.request.method) {
    HttpMethod.post => AuthController.instance.login(context),
    _ => Future.value(Response(statusCode: HttpStatus.methodNotAllowed))
  };
}

But still error:

  • nenuphar gen
    Will generate OpenAPI file
    input is: C:\Users\User\Documents\Project\flutter\other\travel_plan
    Found C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\index.dart
    C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\api\auth\login.dart
    C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\api\auth\register.dart
    C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\api\profile\index.dart
    C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\api\travel\index.dart
    C:\Users\User\Documents\Project\flutter\other\travel_plan/routes\api\travel[id].dart routes
    evaluating path: \index
    evaluating path: \api\auth\login
    evaluating path: \api\auth\register
    evaluating path: \api\profile\index
    evaluating path: \api\travel\index
    evaluating path: \api\travel{id}
    Failed to generate OpenAPI file: Bad state: No element

Thanks for your feeback @yusriltakeuchi

I successfully reproduced your issue and fixed it.

You use case has also been added to the automated tests.

The fix has been tested on Windows 10 and validated.

You can update to 0.0.10 version to get the fix.

Feel free to let me know if you face any other issue.

Thank you for using Nenuphar 🚀

Hi @yusriltakeuchi

Thanks for your e-mail question about basic openapi informations.

You can specify them by editing the nenuphar.json file à the root level of your project.
This file should have been generated by the nenuphar init command.

For more informations please follow the link bellow.

https://piotrfleury.github.io/nenuphar_cli/#nenupharjson-file