openAPI dart generator from java spring-boot does not generate null safety code

Viewed 15

I am using openAPI with a Java spring-boot server to generate client code for a flutter mobile application. The generator I am using is dart.

The generated code does not seem to have null safety. All the model properties are nullable and every request returns an nullable optional value, which forces to put ! everywhere in my code. I am using the adequate Lombok anotations for null safety such as @NonNull. Is this normal?

Here is an example of a generated data class:

@AllArgsConstructor
public class RegistrationResponse {
    @NonNull
    public User user;
    @NonNull
    public boolean isNewUser;
}
class RegistrationResponse {
  /// Returns a new [RegistrationResponse] instance.
  RegistrationResponse({
    this.user,
    this.isNewUser,
  });

  ///
  /// Please note: This property should have been non-nullable! Since the specification file
  /// does not include a default value (using the "default:" property), however, the generated
  /// source code must fall back to having a nullable type.
  /// Consider adding a "default:" property in the specification file to hide this note.
  ///
  Users? user;

  /// same comment
  ///
  bool? isNewUser;
//...
};

Why do I need to have a default value for the property to be nullable?

0 Answers
Related