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

Add validation for ignore feature #267

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
19 changes: 18 additions & 1 deletion resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2670,9 +2670,26 @@ func (r *Resolver) resolveCallExpr(ctx *context, def *federation.CallExpr, build
}

func (r *Resolver) resolveValidationExpr(ctx *context, def *federation.ValidationExpr, builder *source.ValidationExprOptionBuilder) *ValidationExpr {
grpcErr := r.resolveGRPCError(ctx, def.GetError(), builder.WithError())
if grpcErr.Ignore {
ctx.addError(
ErrWithLocation(
`validation doesn't support "ignore" feature`,
builder.WithError().WithIgnore().Location(),
),
)
}
if grpcErr.IgnoreAndResponse != nil {
ctx.addError(
ErrWithLocation(
`validation doesn't support "ignore_and_response" feature`,
builder.WithError().WithIgnoreAndResponse().Location(),
),
)
}
return &ValidationExpr{
Name: def.GetName(),
Error: r.resolveGRPCError(ctx, def.GetError(), builder.WithError()),
Error: grpcErr,
}
}

Expand Down
37 changes: 37 additions & 0 deletions validator/testdata/invalid_validation_with_ignore.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

package federation;

import "federation.proto";

option go_package = "example/federation;federation";

service FederationService {
option (grpc.federation.service) = {};
rpc GetPost(GetPostRequest) returns (GetPostResponse) {};
}

message GetPostRequest {
string id = 1;
}

message GetPostResponse {
option (grpc.federation.message) = {
def {
validation {
error {
if: "true"
ignore: true
}
}
}
def {
validation {
error {
if: "true"
ignore_and_response: "'foo'"
}
}
}
};
}
8 changes: 8 additions & 0 deletions validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ invalid_validation_bad_request.proto:55:32: description must always return a str
invalid_validation_localized_message.proto:54:26: message must always return a string value
54: message: "1"
^
`},
{file: "invalid_validation_with_ignore.proto", expected: `
invalid_validation_with_ignore.proto:24:19: validation doesn't support "ignore" feature
24: ignore: true
^
invalid_validation_with_ignore.proto:32:32: validation doesn't support "ignore_and_response" feature
32: ignore_and_response: "'foo'"
^
`},
{file: "invalid_list_sort.proto", expected: `
invalid_list_sort.proto:55:59: ERROR: <input>:1:14: list(org.federation.User) is not comparable
Expand Down
Loading