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

Just return Optional.empty() when there is nothing to validate #48

Open
alexander-yevsyukov opened this issue Oct 6, 2022 · 0 comments

Comments

@alexander-yevsyukov
Copy link
Collaborator

alexander-yevsyukov commented Oct 6, 2022

I have the following type (it's a part of test data in core-java project):

message MixinCreateProject {
    int32 project_id = 1;
    string name = 2;
}

It's a command (because it resides in the mixin_commands.proto file). As such it has its first field required, but since it's of int32 type it would always have some value. So, we have nothing to validate about this type.

The code of validation generated for this type is this:

public java.util.Optional<io.spine.validate.ValidationError> validate() {
  java.util.ArrayList<io.spine.validate.ConstraintViolation> violations = new java.util.ArrayList<>();
  // INSERT:'extra_validation:type.spine.io/spine.test.mixin.command.MixinCreateProject'
  if (!violations.isEmpty()) {
    return java.util.Optional.of(io.spine.validate.ValidationError.newBuilder().addAllConstraintViolation(violations).build());
      } else {
    return java.util.Optional.empty();
   }
}

It does nothing useful because the array created would be always empty, and there's no code added in the insertion point.

It would be good to have just this instead:

public java.util.Optional<io.spine.validate.ValidationError> validate() {
    return java.util.Optional.empty();
}
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