MCPcopy Create free account
hub / github.com/Botloader/botloader / validate_settings_option_value_list

Function validate_settings_option_value_list

components/validation/src/web.rs:505–571  ·  view source on GitHub ↗
(
    ctx: &mut ValidationContext,
    value: &serde_json::Value,
    context_data: &SettingsOptionList,
    guild_data: Option<&GuildData>,
)

Source from the content-addressed store, hash-verified

503}
504
505pub(crate) fn validate_settings_option_value_list(
506 ctx: &mut ValidationContext,
507 value: &serde_json::Value,
508 context_data: &SettingsOptionList,
509 guild_data: Option<&GuildData>,
510) {
511 let serde_json::Value::Array(v) = value else {
512 ctx.push_error("Invalid type, expected array");
513 return;
514 };
515
516 for (i, item) in v.iter().enumerate() {
517 ctx.push_index(i);
518
519 // let Some(arr) = item.as_array() else {
520 // ctx.push_error("item is not a object");
521 // ctx.pop_field();
522 // continue;
523 // };
524
525 match serde_json::from_value::<Vec<SettingsOptionValue>>(item.clone()) {
526 Ok(fields) => {
527 for field in &fields {
528 let Some(definition) =
529 context_data.template.iter().find(|v| v.name == field.name)
530 else {
531 ctx.push_field_error(&field.name, "unknown field");
532 continue;
533 };
534
535 ctx.push_field(&field.name);
536 validate_settings_option_value_option(
537 ctx,
538 &field.value,
539 definition,
540 guild_data,
541 );
542 ctx.pop_field();
543 }
544
545 // check required fields
546 for field_def in context_data.template.iter().filter(|v| v.required) {
547 if !fields.iter().any(|v| v.name == field_def.name) {
548 ctx.push_field_error(&field_def.name, "required")
549 }
550 }
551 }
552 Err(err) => {
553 ctx.push_error(format!("failed deserializing fields: {}", err));
554 }
555 }
556
557 // validate all fields against the template
558 // for (key, value) in object {
559 // let Some(definition) = context_data.template.iter().find(|v| &v.name == key) else {
560 // ctx.push_field_error(key, "unknown field");
561 // continue;
562 // };

Callers 2

validateMethod · 0.85
validateMethod · 0.85

Calls 6

push_errorMethod · 0.80
push_indexMethod · 0.80
push_field_errorMethod · 0.80
push_fieldMethod · 0.80
pop_fieldMethod · 0.80

Tested by

no test coverage detected