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

Remove Violations messages #261

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/custom-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The `Constraint` message is used to define validation rules for messages or
fields in a message. The constraints are then evaluated using
the `protovalidate` tool to ensure that the data conforms to the specified
rules. If any violations occur during validation, they are reported using
the `Violations` message. The `Violation` message provides detailed information
the `Violation` message. The `Violation` message provides detailed information
about the violated constraint, including the field path, the constraint ID, and
the error message.

Expand Down
28 changes: 5 additions & 23 deletions docs/errors.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
# Errors

## Violation Errors
## Validation Errors

The `Violation` message represents a single violation of a constraint. It has
three fields:

- `field_path`: a machine-readable path to the field that failed validation.
- `constraint_id`: the id of the constraint that failed validation.
- `message`: a human-readable error message for this violation.

### Violations

The `Violations` message is used to collect all violations that occur during
constraint validation. It has one field:

- `violations`: a repeated field of `Violation` messages. `Violations` are
returned by `protovalidate` when a message fails to fulfill the requirements
of the constraint validation.

In summary, the `Constraints` and `Violations` messages provide a way to define
and enforce validation constraints using the Common Expression Language (CEL)
syntax. Standard constraints are defined using the `Constraints` message and
provide a set of predefined validation rules that can be applied to various.
These messages can be used to ensure that the data conforms to the
specified rules and to report any violations that occur during validation.
A validation error collects constraint violations encountered during validation.
A violation represents a single violation of a constraint. It contains a machine
readable field path, the constraint ID and a human-readable error diagostic for
the violation. A validation error contains one or more violations.

## Compilation Errors

Expand Down
37 changes: 0 additions & 37 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Buf Technologies, Inc.

Check failure on line 1 in proto/protovalidate/buf/validate/validate.proto

View workflow job for this annotation

GitHub Actions / buf

Previously present message "Violation" was deleted from file.

Check failure on line 1 in proto/protovalidate/buf/validate/validate.proto

View workflow job for this annotation

GitHub Actions / buf

Previously present message "Violations" was deleted from file.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -4748,40 +4748,3 @@
// [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
extensions 1000 to max;
}

// `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.
optional 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.
optional 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.
optional string message = 3;

// `for_key` indicates whether the violation was caused by a map key, rather than a value.
optional bool for_key = 4;
}
Loading
Loading