Skip to content

[BUG] Nullable query or param annotated data types are not working. #93

@ShreemanMassTech

Description

@ShreemanMassTech

🐛 Bug Report

Whenever a nullable parameter/query annotated with @query or @param , the generated swagger have wrong type for the paramter and generated coe not able to parse/handle the nullable case.

📄 Code

import 'package:vaden/vaden.dart';

@Api(tag: 'Fibo', description: 'FiboSeriesController')
@Controller("/fibo")
class FiboSeriesController {
  @Get('/fibonacci')
  Future<String> getFibonacciSeries(@Query('n') int? n) async {
    if (n == null) {
      return "Please provide a number";
    }
    List<int> fiboSeries = [0, 1];
    while (fiboSeries.last < n) {
      fiboSeries.add(
        fiboSeries.last + fiboSeries.last - fiboSeries[0],
      ); // This line is the key to the Fibonacci series
    }
    return fiboSeries.toString();
  }
}

Expected Result

Nullable query parameter should check types accordingly return missing query or param paramters and return result.

[0, 1, 2, 4, 8, 16, 32, 64]

Actual Result

Terminal Error

type 'String' is not a subtype of type 'int?' in type cast
#0      VadenApplicationImpl._parse (package:portfolio/vaden_application.dart:374:20)
#1      VadenApplicationImpl.setup.<anonymous closure> (package:portfolio/vaden_application.dart:216:17)
#2      RouterEntry.invoke.<anonymous closure> (package:shelf_router/src/router_entry.dart:107:30)
#3      RouterEntry.invoke (package:shelf_router/src/router_entry.dart:113:7)
#4      Router.call (package:shelf_router/src/router.dart:184:38)
#5      Router.mount.<anonymous closure> (package:shelf_router/src/router.dart:167:23)
#6      RouterEntry.invoke.<anonymous closure> (package:shelf_router/src/router_entry.dart:107:30)
#7      RouterEntry.invoke (package:shelf_router/src/router_entry.dart:113:7)
#8      Router.call (package:shelf_router/src/router.dart:184:38)
<asynchronous suspension>
#9      VadenApplicationImpl.run.<anonymous closure> (package:portfolio/vaden_application.dart:40:26)
<asynchronous suspension>
#10     CalculateTotalTimeMiddleware.handler (package:portfolio/config/app_configuration.dart:51:22)
<asynchronous suspension>
#11     logRequests.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:shelf/src/middleware/logger.dart:30:62)
<asynchronous suspension>
#12     EnforceJsonContentType.handler (package:vaden/src/middlewares/enforce_json_content_type.dart:48:22)
<asynchronous suspension>
#13     cors.<anonymous closure>.<anonymous closure> (package:vaden/src/middlewares/cors.dart:67:24)
<asynchronous suspension>
#14     handleRequest (package:shelf/shelf_io.dart:140:16)
<asynchronous suspension>

Total time taken: 13 ms
2025-05-05T22:44:42.774758  0:00:00.011944 GET     [500] /fibo/fibonacci?n=58

API Response

{
    "error": "Internal server error"
}

📷 Evidence

Image Image

⚠️ Severity

  • Low
  • Medium
  • High
  • Critical

🚨 Priority

  • P1 (High)
  • P2 (Medium)
  • P3 (Low)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions