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

feat: apikey security in body - arrays #139

Merged
merged 2 commits into from
Jul 19, 2024
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
58 changes: 29 additions & 29 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions core/core_to_map_std/src/unstable/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,27 @@ pub fn resolve_security(
)));
}

let mut key_idx: usize = 0;
let mut nested = &mut body;

while key_idx < keys.len() - 1 {
nested = &mut nested[keys[key_idx]];

if !nested.is_object() {
for (key_idx, key) in keys.iter().enumerate() {
if nested.is_array() {
let key_number = match key.parse::<usize>() {
Ok(n) => n,
Err(_) => return Err(HttpCallError::InvalidSecurityConfiguration(format!(
"Field value on path '/{}' is an array but provided key cannot be parsed as a number",
&keys[0..=key_idx].join("/")
)))
};
nested = &mut nested[key_number];
} else if nested.is_object() {
nested = &mut nested[key];
} else {
return Err(HttpCallError::InvalidSecurityConfiguration(format!(
"Field values on path '/{}' isn't object",
&keys[0..key_idx + 1].join("/")
"Field value on path '/{}' must be an object or an array",
&keys[0..=key_idx].join("/")
)));
}

key_idx += 1;
}

nested[keys[key_idx]] = serde_json::Value::from(apikey.to_string());
*nested = serde_json::Value::from(apikey.to_string());

params.body = Some(serde_json::to_vec(&body).map_err(|e| {
HttpCallError::InvalidSecurityConfiguration(format!(
Expand Down
2 changes: 1 addition & 1 deletion core/json_schemas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dependencies]
serde_json = { workspace = true }
serde_yaml = { version = "0.9" }
serde_yaml = { version = "0.9.32" }

[dev-dependencies]
jsonschema = { workspace = true }