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

Update examples for new option ignore #147

Closed
wants to merge 2 commits into from
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 examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proto_library(
"option_duration_range.proto",
"option_enum_allow_values.proto",
"option_enum_disallow_values.proto",
"option_field_ignore_empty.proto",
"option_field_ignore.proto",
"option_field_presence.proto",
"option_field_skip_validation.proto",
"option_map.proto",
Expand Down
51 changes: 51 additions & 0 deletions examples/option_field_ignore.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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";

import "buf/validate/validate.proto";

service ProfileService {
rpc CreateProfile(CreateProfileRequest) returns (CreateProfileResponse);
rpc UpdateProfile(UpdateProfileRequest) returns (UpdateProfileResponse);
}

message CreateProfileRequest {
string name = 1 [(buf.validate.field).required = true];
string email = 2 [
(buf.validate.field).string.email = true,
// If email field is left empty, it's not validated.
(buf.validate.field).ignore = IGNORE_EMPTY
];
string description = 3;
}

message UpdateProfileRequest {
uint64 id = 1;
// The following fields are optional as this is an update request.
optional string name = 2;
optional string email = 3 [
(buf.validate.field).string.email = true,
// `IGNORE_DEFAULT` is used here:
// If this field is unpopulated, we don't validate it as an email.
// If this field is populated and is set to the empty string (the default
// value), it is also ignored. This is to allow users to unset their emails.
(buf.validate.field).ignore = IGNORE_DEFAULT
];
optional string description = 4;
}

message CreateProfileResponse {}

message UpdateProfileResponse {}
36 changes: 0 additions & 36 deletions examples/option_field_ignore_empty.proto

This file was deleted.

4 changes: 2 additions & 2 deletions examples/option_number_allow_values.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ service CarService {

message SearchCarRequest {
optional fixed32 number_of_seats = 1 [(buf.validate.field) = {
// `ignore_empty` skips validation if the field isn't set.
ignore_empty: true,
// `IGNORE_EMPTY` skips validation if the field isn't set.
ignore: IGNORE_EMPTY,
fixed32: {
// `in` requires that the value must be one of the specified values.
// In this case, it validates that the number of seats is either 5 or 7.
Expand Down
2 changes: 1 addition & 1 deletion examples/option_number_range.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message CreateReviewRequest {
message CreateReviewResponse {
// aggregated_review is the aggregated review after this one in request is created.
// This value is empty if there are less than a 100 reviews submitted.
AggregatedReview aggregated_review = 1 [(buf.validate.field).ignore_empty = true];
AggregatedReview aggregated_review = 1 [(buf.validate.field).ignore = IGNORE_EMPTY];
}

message AggregatedReview {
Expand Down
4 changes: 2 additions & 2 deletions examples/option_string_match_pattern.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message UserProfile {
// must match it.
pattern: "^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$",
},
ignore_empty: true,
ignore: IGNORE_EMPTY,
}];
// `hostname` specifies that the field value must be a valid hostname as defined
// by [RFC 1034](https://tools.ietf.org/html/rfc1034#section-3.5).
Expand All @@ -43,7 +43,7 @@ message UserProfile {
// defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3).
// (buf.validate.field).string.uri_ref = true,
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore_empty = true
(buf.validate.field).ignore = IGNORE_EMPTY
];
// `ip` specifies that a string field must be a valid ip address, in either v4 or v6.
string last_login_at = 6 [(buf.validate.field).string.ip = true];
Expand Down