SpineEventEngine / validation

Apache License 2.0
3 stars 0 forks source link

Validate `Any` properly and migrate to the latest ProtoData API #28

Closed armiol closed 2 years ago

armiol commented 2 years ago

This is a part 2 of the changes aiming to address the circular dependencies between mc-java, ProtoData and validation modules.

See this PR in mc-java for the part 1.

Addressing the circular dependencies

Also, in scope of this changeset, the following updates were made:

  1. Migration to the latest mc-java.
  2. Migration to the latest ProtoData.
  3. Turning off the modelCompiler's validation in this repository.

The last point is necessary to avoid any version conflicts between the validation artifacts under-development (and published from this repo during the build in scope of integration testing) and those brought by the modelCompiler in case its validation capabilities are enabled.

TLDR; we cannot disable modelCompiler for this repo altogether, since the machinery generating the validation code is itself a Spine application. Therefore, it requires all the standard features such as recognising events and commands, generating the Spine-specific marker interfaces etc.

One more thing here to note is that Gradle syntax does not allow to apply and configure third-party plugins such as modelCompiler in a single build file. Therefore, some modules in this repository were restructured into a root Gradle project and a sub-module — to turn off the modelCompiler's validation for the sub-module.

Improving the generated code

In addition to resolving the circular dependencies, this PR fixes the generated validation code. Previously, the code fragment like this one was resulting in a non-compilable validation code, generated by this library:

message Sample {
    // ...
    google.protobuf.Any something_to_validate = 2 [(validate) = true];
}

In this update, the generated validation code for Any-typed fields with enabled in-depth validation was fixed.

Another fix is related to the comparison operations used in the generated validation code related to time_options.proto. Previously, TIME_UNDEFINED values participating in the validation at runtime, were handled incorrectly, which was leading to a runtime exception.

The library version was set to 2.0.0-SNAPSHOT.19.

In the following PRs, mc-java will be migrated to this version of Validation artifacts. Also, ProtoData will be migrated to the latest mc-java changes along with addressing its vulnerabilities.

codecov[bot] commented 2 years ago

Codecov Report

Merging #28 (e58a8d7) into master (641ce58) will decrease coverage by 0.18%. The diff coverage is 0.00%.

@@             Coverage Diff             @@
##             master     #28      +/-   ##
===========================================
- Coverage      9.34%   9.16%   -0.19%     
  Complexity       46      46              
===========================================
  Files            61      61              
  Lines          1413    1441      +28     
  Branches        124     127       +3     
===========================================
  Hits            132     132              
- Misses         1267    1295      +28     
  Partials         14      14              
armiol commented 2 years ago

@alexander-yevsyukov PTAL.