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

[REQ][Dart] Generator adds unnecessary null handling for non-nullable primitive responses #20266

Open
poka-IT opened this issue Dec 6, 2024 · 0 comments

Comments

@poka-IT
Copy link

poka-IT commented Dec 6, 2024

Description:
The Dart generator adds unnecessary null handling code for non-nullable primitive responses, making the return type nullable when it shouldn't be.
Is there an option to prevent this behavior?

Current behavior:

Future<bool?> hasUnreadNotification() async {
  final response = await hasUnreadNotificationWithHttpInfo();
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'bool',) as bool;
  }
  return null;
}

Expected behavior:

Future<bool> hasUnreadNotification() async {
  final response = await hasUnreadNotificationWithHttpInfo();
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'bool',) as bool;
}

Backend endpoint:

@GetMapping("/has-unread-notification")
fun hasUnreadNotification(): Boolean {
    return dashboardService.hasUnreadNotification()
}

Version:

  • OpenAPI Generator: 7.10.0
  • Dart SDK: 3.24.3

Additional context:
The backend endpoint always returns a non-nullable boolean, but the generator adds unnecessary null handling code and makes the return type nullable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant