Skip to content

Commit

Permalink
OpenRPC Validator: Not always returning method result schema (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
pahearn73 authored Nov 14, 2024
1 parent 03bd06a commit e16b2ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "1.14.rc" ]
branches: [ "main", "1.16.rc" ]

env:
CARGO_TERM_COLOR: always
Expand Down
25 changes: 23 additions & 2 deletions openrpc_validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,24 @@ impl FireboltOpenRpc {
None
}

fn get_result_property(
&self,
result_schema_map: &Map<String, Value>,
rpc_method: &RpcMethod,
) -> Map<String, Value> {
let mut result_map = Map::new();
let result_value = result_schema_map.get("type").unwrap_or(&Value::Null);
result_map.insert(rpc_method.result.name.clone(), result_value.clone());
result_map
}

pub fn get_result_properties_schema_by_name(&self, name: &str) -> Option<Map<String, Value>> {
if let Some(method) = self.get_method_by_name(name) {
if let Some(result_schema_map) = method.result.schema.as_object() {
if let Some(any_of_map) = result_schema_map.get("anyOf") {
// Iterate the anyOf type array and get the first one that matches. With the current firebolt APIs it will happen
// to be the correct type, but this is extremely fragile and should be addressed in a future firebolt revision.
// Ripple needs a way to determine the explicit result type.
if let Some(any_of_array) = any_of_map.as_array() {
for value in any_of_array.iter() {
if let Some(result_properties_map) =
Expand All @@ -128,11 +142,18 @@ impl FireboltOpenRpc {
}
}
} else {
// This should never happen as it indicates a schema error.
return None;
}
} else {
return self.get_result_ref_schemas(result_schema_map);
} else if let Some(result_properties_map) =
self.get_result_ref_schemas(result_schema_map)
{
// Return the resolved $ref properites.
return Some(result_properties_map);
}

// The type is a non-object, just return it.
return Some(self.get_result_property(result_schema_map, &method));
}
}
None
Expand Down

0 comments on commit e16b2ed

Please sign in to comment.