fn random_json(rng: &mut SmallRng, prop: Option<&PropertyInstance>, size: usize) -> String {
    let code = match prop {
        Some(p) => {
            match p {
                PropertyInstance::Null => "null".to_string(),
                PropertyInstance::Boolean(_) => {
                    if rng.gen_bool(0.5) {
                        "true".to_string()
                    } else {
                        "false".to_string()
                    }
                }
                PropertyInstance::Integer { .. } => {
                    format!("\"{}\"", random_number(rng, size))
                }
                PropertyInstance::Number { ..  } => {
                    format!("\"{}\"", random_number(rng, size))
                }
                PropertyInstance::Array { items } => random_json_list(rng, Some(&*items), size),
                PropertyInstance::Object {
                    properties,
                    ..
                } => {
                    let mut ret = "{\"".to_string();

                    for (name, prop) in properties {
                        ret.push_str(name);
                        match prop {
                            Property::Value(p) => {
                                ret.push_str(
                                    format!("\": {},", random_json(rng, Some(p), size)).as_str(),
                                );
                            }
                            Property::Ref(refp) => {
                                ret.push_str(refp.reference.as_str());
                                ret.push_str(",");
                            }
                        }
                    }

                    if ret.len() > 1 {
                        ret.pop();
                    }
                    ret.push_str("}");
                    ret
                }
                PropertyInstance::String => format!("\"{}\"", random_string(rng, size)),
            }
        }
        None => match rng.gen_range(0..10) {
            0 => "true".to_string(),
            1 => "false".to_string(),
            2 => "null".to_string(),
            3 => format!("\"{}\"", random_number(rng, size)),
            4 => format!("\"{}\"", random_string(rng, size)),
            5 => random_json_list(rng, None, size),
            _ => random_json_dict(rng, size),
        },
    };
    code
}
/*
    Generates random JSON (used to generate POST/PATCH request's body)
    If available it can use information from requestBody's schema.

    TODO:
    The serde-json-schema crate used to parse the requestBody schema
    is limited/incomplete and doesn't allow us to extract all the
    information needed to generate proper JSON. It will be replaced by
    "jtd" and follow a similar generation approach to:
    https://github.com/jsontypedef/json-typedef-fuzz/blob/master/src/lib.rs

*/
Generates random JSON (used to generate POST/PATCH request's body)
If available it can use information from requestBody's schema.

The serde-json-schema crate used to parse the requestBody schema
is limited/incomplete and doesn't allow us to extract all the
information needed to generate proper JSON.
Generates random JSON ( used to generate POST / PATCH request ' s body ) If available it can use information from requestBody ' s schema . The serde - json - schema crate used to parse the requestBody schema is limited / incomplete and doesn ' t allow us to extract all the information needed to generate proper JSON .
fn random_json(rng: &mut SmallRng, prop: Option<&PropertyInstance>, size: usize) -> String {
    let code = match prop {
        Some(p) => {
            match p {
                PropertyInstance::Null => "null".to_string(),
                PropertyInstance::Boolean(_) => {
                    if rng.gen_bool(0.5) {
                        "true".to_string()
                    } else {
                        "false".to_string()
                    }
                }
                PropertyInstance::Integer { .. } => {
                    format!("\"{}\"", random_number(rng, size))
                }
                PropertyInstance::Number { ..  } => {
                    format!("\"{}\"", random_number(rng, size))
                }
                PropertyInstance::Array { items } => random_json_list(rng, Some(&*items), size),
                PropertyInstance::Object {
                    properties,
                    ..
                } => {
                    let mut ret = "{\"".to_string();
                    for (name, prop) in properties {
                        ret.push_str(name);
                        match prop {
                            Property::Value(p) => {
                                ret.push_str(
                                    format!("\": {},", random_json(rng, Some(p), size)).as_str(),
                                );
                            }
                            Property::Ref(refp) => {
                                ret.push_str(refp.reference.as_str());
                                ret.push_str(",");
                            }
                        }
                    }
                    if ret.len() > 1 {
                        ret.pop();
                    }
                    ret.push_str("}");
                    ret
                }
                PropertyInstance::String => format!("\"{}\"", random_string(rng, size)),
            }
        }
        None => match rng.gen_range(0..10) {
            0 => "true".to_string(),
            1 => "false".to_string(),
            2 => "null".to_string(),
            3 => format!("\"{}\"", random_number(rng, size)),
            4 => format!("\"{}\"", random_string(rng, size)),
            5 => random_json_list(rng, None, size),
            _ => random_json_dict(rng, size),
        },
    };
    code
}
fn random_json ( rng : & mut SmallRng , prop : Option < & PropertyInstance > , size : usize ) -> String { let code = match prop { Some ( p ) => { match p { PropertyInstance :: Null => " " . to_string ( ) , PropertyInstance :: Boolean ( _ ) => { if rng . gen_bool ( 0.5 ) { " " . to_string ( ) } else { " " . to_string ( ) } } PropertyInstance :: Integer { .. } => { format ! ( " \" \" " random_number ( rng size ) ) } PropertyInstance :: Number { .. } => { format ! ( " \" \" " random_number ( rng size ) ) } PropertyInstance :: Array { items } => random_json_list ( rng , Some ( & * items ) , size ) , PropertyInstance :: Object { properties , .. } => { let mut ret = " \" " . to_string ( ) ; for ( name , prop ) in properties { ret . push_str ( name ) ; match prop { Property :: Value ( p ) => { ret . push_str ( format ! ( " \" " random_json ( rng Some ( p ) size ) ) . as_str ( ) , ) ; } Property :: Ref ( refp ) => { ret . push_str ( refp . reference . as_str ( ) ) ; ret . push_str ( " " ) ; } } } if ret . len ( ) > 1 { ret . pop ( ) ; } ret . push_str ( " " ) ; ret } PropertyInstance :: String => format ! ( " \" \" " random_string ( rng size ) ) , } } None => match rng . gen_range ( 0 .. 10 ) { 0 => " " . to_string ( ) , 1 => " " . to_string ( ) , 2 => " " . to_string ( ) , 3 => format ! ( " \" \" " random_number ( rng size ) ) , 4 => format ! ( " \" \" " random_string ( rng size ) ) , 5 => random_json_list ( rng , None , size ) , _ => random_json_dict ( rng , size ) , } , } ; code }
Generates random JSON (used to generate POST/PATCH request's body)
If available it can use information from requestBody's schema.
Generates random JSON ( used to generate POST / PATCH request ' s body ) If available it can use information from requestBody ' s schema .
rng
&mut SmallRng
prop
Option<&PropertyInstance>
size
usize