Skip to content

Commit

Permalink
Include proto files in jar file (#35)
Browse files Browse the repository at this point in the history
Update the generate task to export the module from the BSR to
src/main/resources, so the .proto files will be included in the final
.jar file.

Fixes #15.
  • Loading branch information
pkwarren authored Sep 11, 2023
1 parent c800411 commit 9d1946d
Show file tree
Hide file tree
Showing 4 changed files with 3,830 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2023
LICENSE_IGNORE :=
LICENSE_IGNORE := --ignore src/main/java/build/buf/validate/ --ignore conformance/src/main/java/build/buf/validate/conformance/
JAVA_VERSION = 20
JAVAC = javac
JAVA = java
Expand Down Expand Up @@ -60,7 +60,8 @@ help: ## Describe useful make targets

.PHONY: generate
generate: $(BIN)/buf generate-license ## Regenerate code and license headers
$(BIN)/buf generate --template buf.gen.yaml buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION)
$(BIN)/buf export buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION) --output src/main/resources
$(BIN)/buf generate --template buf.gen.yaml src/main/resources
$(BIN)/buf generate --template conformance/buf.gen.yaml -o conformance/ buf.build/bufbuild/protovalidate-testing:$(PROTOVALIDATE_VERSION)

.PHONY: lint
Expand Down
92 changes: 92 additions & 0 deletions src/main/resources/buf/validate/expression.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package buf.validate;

option go_package = "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate";
option java_multiple_files = true;
option java_outer_classname = "ExpressionProto";
option java_package = "build.buf.validate";

// `Constraint` represents a validation rule written in the Common Expression
// Language (CEL) syntax. Each Constraint includes a unique identifier, an
// optional error message, and the CEL expression to evaluate. For more
// information on CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md).
//
// ```proto
// message Foo {
// option (buf.validate.message).cel = {
// id: "foo.bar"
// message: "bar must be greater than 0"
// expression: "this.bar > 0"
// };
// int32 bar = 1;
// }
// ```
message Constraint {
// `id` is a string that serves as a machine-readable name for this Constraint.
// It should be unique within its scope, which could be either a message or a field.
string id = 1;

// `message` is an optional field that provides a human-readable error message
// for this Constraint when the CEL expression evaluates to false. If a
// non-empty message is provided, any strings resulting from the CEL
// expression evaluation are ignored.
string message = 2;

// `expression` is the actual CEL expression that will be evaluated for
// validation. This string must resolve to either a boolean or a string
// value. If the expression evaluates to false or a non-empty string, the
// validation is considered failed, and the message is rejected.
string expression = 3;
}

// `Violations` is a collection of `Violation` messages. This message type is returned by
// protovalidate when a proto message fails to meet the requirements set by the `Constraint` validation rules.
// Each individual violation is represented by a `Violation` message.
message Violations {
// `violations` is a repeated field that contains all the `Violation` messages corresponding to the violations detected.
repeated Violation violations = 1;
}

// `Violation` represents a single instance where a validation rule, expressed
// as a `Constraint`, was not met. It provides information about the field that
// caused the violation, the specific constraint that wasn't fulfilled, and a
// human-readable error message.
//
// ```json
// {
// "fieldPath": "bar",
// "constraintId": "foo.bar",
// "message": "bar must be greater than 0"
// }
// ```
message Violation {
// `field_path` is a machine-readable identifier that points to the specific field that failed the validation.
// This could be a nested field, in which case the path will include all the parent fields leading to the actual field that caused the violation.
string field_path = 1;

// `constraint_id` is the unique identifier of the `Constraint` that was not fulfilled.
// This is the same `id` that was specified in the `Constraint` message, allowing easy tracing of which rule was violated.
string constraint_id = 2;

// `message` is a human-readable error message that describes the nature of the violation.
// This can be the default error message from the violated `Constraint`, or it can be a custom message that gives more context about the violation.
string message = 3;

// `for_key` indicates whether the violation was caused by a map key, rather than a value.
bool for_key = 4;
}
41 changes: 41 additions & 0 deletions src/main/resources/buf/validate/priv/private.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package buf.validate.priv;

import "google/protobuf/descriptor.proto";

option go_package = "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate/priv";
option java_multiple_files = true;
option java_outer_classname = "PrivateProto";
option java_package = "build.buf.validate.priv";

extend google.protobuf.FieldOptions {
// Do not use. Internal to protovalidate library
optional FieldConstraints field = 1160;
}

// Do not use. Internal to protovalidate library
message FieldConstraints {
repeated Constraint cel = 1;
}

// Do not use. Internal to protovalidate library
message Constraint {
string id = 1;
string message = 2;
string expression = 3;
}
Loading

0 comments on commit 9d1946d

Please sign in to comment.