fix: apply generators to the request in the same manor as the response
@@ -1375,14 +1375,22 @@ pub fn match_message(expected: &models::message::Message, actual: &models::messa
/// Generates the request by applying any defined generators
pub fn generate_request(request: &models::Request, mode: &GeneratorTestMode, context: &HashMap<&str, Value>) -> models::Request {
- let generators = request.generators.clone();
let mut request = request.clone();
- generators.apply_generator(mode, &GeneratorCategory::PATH, |_, generator| {
+
+ let generators = request.build_generators(&GeneratorCategory::PATH);
+ if !generators.is_empty() {
+ debug!("Applying path generator...");
+ apply_generators(mode, &generators, &mut |_, generator| {
if let Ok(v) = generator.generate_value(&request.path, context) {
request.path = v;
}
});
- generators.apply_generator(mode, &GeneratorCategory::HEADER, |key, generator| {
+ }
+
+ let generators = request.build_generators(&GeneratorCategory::HEADER);
+ if !generators.is_empty() {
+ debug!("Applying header generators...");
+ apply_generators(mode, &generators, &mut |key, generator| {
if let Some(ref mut headers) = request.headers {
if headers.contains_key(key) {
if let Ok(v) = generator.generate_value(&headers.get(key).unwrap().clone(), context) {
@@ -1391,7 +1399,12 @@ pub fn generate_request(request: &models::Request, mode: &GeneratorTestMode, con
}
}
});
- generators.apply_generator(mode, &GeneratorCategory::QUERY, |key, generator| {
+ }
+
+ let generators = request.build_generators(&GeneratorCategory::QUERY);
+ if !generators.is_empty() {
+ debug!("Applying query generators...");
+ apply_generators(mode, &generators, &mut |key, generator| {
if let Some(ref mut parameters) = request.query {
if let Some(parameter) = parameters.get_mut(key) {
let mut generated = parameter.clone();
@@ -1404,8 +1417,15 @@ pub fn generate_request(request: &models::Request, mode: &GeneratorTestMode, con
}
}
});
- request.body = generators.apply_body_generators(mode, &request.body, request.content_type(),
- context);
+ }
+
+ let generators = request.build_generators(&GeneratorCategory::BODY);
+ if !generators.is_empty() && request.body.is_present() {
+ debug!("Applying body generators...");
+ request.body = apply_body_generators(mode, &request.body, request.content_type(),
+ context, &generators);
+ }
+
request
}
@@ -1424,7 +1444,7 @@ pub fn generate_response(response: &models::Response, mode: &GeneratorTestMode,
}
let generators = response.build_generators(&GeneratorCategory::HEADER);
if !generators.is_empty() {
- debug!("Applying headers generators...");
+ debug!("Applying header generators...");
apply_generators(mode, &generators, &mut |key, generator| {
if let Some(ref mut headers) = response.headers {
if headers.contains_key(key) {
