From 8560cfdb24de1756cbbc31727a2cceeb6a3d76b4 Mon Sep 17 00:00:00 2001 From: Wesley Matos Date: Thu, 29 Feb 2024 01:11:37 -0300 Subject: [PATCH] refactor: revert change on validator return --- src/blueprint/mustache.rs | 5 ++--- src/blueprint/operators/graphql.rs | 8 +++----- src/blueprint/operators/grpc.rs | 7 ++++--- src/blueprint/operators/http.rs | 12 +++++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/blueprint/mustache.rs b/src/blueprint/mustache.rs index 460b2980d5..c8db6d667e 100644 --- a/src/blueprint/mustache.rs +++ b/src/blueprint/mustache.rs @@ -101,14 +101,14 @@ impl<'a> MustachePartsValidator<'a> { } impl FieldDefinition { - pub fn validate_field(self, type_of: &config::Type, config: &Config) -> Valid { + pub fn validate_field(&self, type_of: &config::Type, config: &Config) -> Valid<(), String> { // XXX we could use `Mustache`'s `render` method with a mock // struct implementing the `PathString` trait encapsulating `validation_map` // but `render` simply falls back to the default value for a given // type if it doesn't exist, so we wouldn't be able to get enough // context from that method alone // So we must duplicate some of that logic here :( - let parts_validator = MustachePartsValidator::new(type_of, config, &self); + let parts_validator = MustachePartsValidator::new(type_of, config, self); match &self.resolver { Some(Expression::IO(IO::Http { req_template, .. })) => { @@ -168,6 +168,5 @@ impl FieldDefinition { } _ => Valid::succeed(()), } - .map_to(self) } } diff --git a/src/blueprint/operators/graphql.rs b/src/blueprint/operators/graphql.rs index bc1b55d50a..ddf21081df 100644 --- a/src/blueprint/operators/graphql.rs +++ b/src/blueprint/operators/graphql.rs @@ -49,11 +49,9 @@ pub fn update_graphql<'a>( return Valid::succeed(b_field); }; - compile_graphql(config, operation_type, graphql).and_then(|resolver| { - b_field - .resolver(Some(resolver)) - .validate_field(type_of, config) - }) + compile_graphql(config, operation_type, graphql) + .map(|resolver| b_field.resolver(Some(resolver))) + .and_then(|b_field| b_field.validate_field(type_of, config).map_to(b_field)) }, ) } diff --git a/src/blueprint/operators/grpc.rs b/src/blueprint/operators/grpc.rs index 2cdcb837c8..8b3ddd230b 100644 --- a/src/blueprint/operators/grpc.rs +++ b/src/blueprint/operators/grpc.rs @@ -215,10 +215,11 @@ pub fn update_grpc<'a>( grpc, validate_with_schema: true, }) - .and_then(|resolver| { + .map(|resolver| b_field.resolver(Some(resolver))) + .and_then(|b_field| { b_field - .resolver(Some(resolver)) - .validate_field(type_of, &config_module.config) + .validate_field(type_of, config_module) + .map_to(b_field) }) }, ) diff --git a/src/blueprint/operators/http.rs b/src/blueprint/operators/http.rs index 05b9d7b97e..78dfceac50 100644 --- a/src/blueprint/operators/http.rs +++ b/src/blueprint/operators/http.rs @@ -80,11 +80,13 @@ pub fn update_http<'a>( return Valid::succeed(b_field); }; - compile_http(config_module, field, http).and_then(|resolver| { - b_field - .resolver(Some(resolver)) - .validate_field(type_of, &config_module.config) - }) + compile_http(config_module, field, http) + .map(|resolver| b_field.resolver(Some(resolver))) + .and_then(|b_field| { + b_field + .validate_field(type_of, config_module) + .map_to(b_field) + }) }, ) }