/// Compute diffs based on a spec and an interaction.
///
/// Will first try to match the interaction to a Request + Response pair from the spec. From there
/// will either produce unmatched results or proceed to diff bodies of the Request and Response
/// respectively.
Compute diffs based on a spec and an interaction.
Will first try to match the interaction to a Request + Response pair from the spec. From there
will either produce unmatched results or proceed to diff bodies of the Request and Response
respectively.
Compute diffs based on a spec and an interaction . Will first try to match the interaction to a Request + Response pair from the spec . From there will either produce unmatched results or proceed to diff bodies of the Request and Response respectively .
pub fn diff(
  spec_projection: &SpecProjection,
  http_interaction: HttpInteraction,
  config: &DiffConfig,
) -> Vec<InteractionDiffResult> {
  let endpoint_projection = spec_projection.endpoint();
  let endpoint_queries = EndpointQueries::new(endpoint_projection);
  let interaction_traverser = traverser::Traverser::new(&endpoint_queries);
  let mut diff_visitors = visitors::diff::DiffVisitors::new();
  interaction_traverser.traverse(&http_interaction, &mut diff_visitors);
  let results = diff_visitors.take_results().unwrap();
  results
    .into_iter()
    .flat_map(move |result| match result {
      InteractionDiffResult::MatchedQueryParameters(result) => {
        let maybe_query_params: Option<BodyDescriptor> = (&http_interaction.request.query).into();
        let query_params = maybe_query_params.or_else(|| Some(BodyDescriptor::empty_object()));
        let shape_diff_results =
          diff_shape(spec_projection.shape(), query_params, &result.root_shape_id);
        shape_diff_results
          .into_iter()
          .map(|shape_diff| {
            InteractionDiffResult::UnmatchedQueryParametersShape(
              result.clone().into_shape_diff(shape_diff),
            )
          })
          .collect()
      }
      InteractionDiffResult::MatchedRequestBodyContentType(result) => {
        // eprintln!("shape diffing for matched a request body content type");
        let body = &http_interaction.request.body.value;
        let shape_diff_results =
          diff_shape(spec_projection.shape(), body.into(), &result.root_shape_id);
        shape_diff_results
          .into_iter()
          .map(|shape_diff| {
            InteractionDiffResult::UnmatchedRequestBodyShape(
              result.clone().into_shape_diff(shape_diff),
            )
          })
          .collect()
      }
      InteractionDiffResult::MatchedResponseBodyContentType(result) => {
        // eprintln!(
        //   "interaction-diff: shape diffing for matched a response body content type: {:?}",
        //   &http_interaction.response.body
        // );
        let body = &http_interaction.response.body.value;
        let shape_diff_results =
          diff_shape(spec_projection.shape(), body.into(), &result.root_shape_id);
        shape_diff_results
          .into_iter()
          .map(|shape_diff| {
            InteractionDiffResult::UnmatchedResponseBodyShape(
              result.clone().into_shape_diff(shape_diff),
            )
          })
          .collect()
      }
      _ => vec![result],
    })
    .filter(|result| {
      // filter out any left-over results that aren't for outside consumoption
      !matches!(
        result,
        InteractionDiffResult::UnmatchedQueryParameters(UnmatchedQueryParameters::Unobserved(_)),
      )
    })
    .collect()
}
pub fn diff ( spec_projection : & SpecProjection , http_interaction : HttpInteraction , config : & DiffConfig , ) -> Vec < InteractionDiffResult > { let endpoint_projection = spec_projection . endpoint ( ) ; let endpoint_queries = EndpointQueries :: new ( endpoint_projection ) ; let interaction_traverser = traverser :: Traverser :: new ( & endpoint_queries ) ; let mut diff_visitors = visitors :: diff :: DiffVisitors :: new ( ) ; interaction_traverser . traverse ( & http_interaction , & mut diff_visitors ) ; let results = diff_visitors . take_results ( ) . unwrap ( ) ; results . into_iter ( ) . flat_map ( move | result | match result { InteractionDiffResult :: MatchedQueryParameters ( result ) => { let maybe_query_params : Option < BodyDescriptor > = ( & http_interaction . request . query ) . into ( ) ; let query_params = maybe_query_params . or_else ( | | Some ( BodyDescriptor :: empty_object ( ) ) ) ; let shape_diff_results = diff_shape ( spec_projection . shape ( ) , query_params , & result . root_shape_id ) ; shape_diff_results . into_iter ( ) . map ( | shape_diff | { InteractionDiffResult :: UnmatchedQueryParametersShape ( result . clone ( ) . into_shape_diff ( shape_diff ) , ) } ) . collect ( ) } InteractionDiffResult :: MatchedRequestBodyContentType ( result ) => { // eprintln!("shape diffing for matched a request body content type"); let body = & http_interaction . request . body . value ; let shape_diff_results = diff_shape ( spec_projection . shape ( ) , body . into ( ) , & result . root_shape_id ) ; shape_diff_results . into_iter ( ) . map ( | shape_diff | { InteractionDiffResult :: UnmatchedRequestBodyShape ( result . clone ( ) . into_shape_diff ( shape_diff ) , ) } ) . collect ( ) } InteractionDiffResult :: MatchedResponseBodyContentType ( result ) => { // eprintln!( //   "interaction-diff: shape diffing for matched a response body content type: {:?}", //   &http_interaction.response.body // ); let body = & http_interaction . response . body . value ; let shape_diff_results = diff_shape ( spec_projection . shape ( ) , body . into ( ) , & result . root_shape_id ) ; shape_diff_results . into_iter ( ) . map ( | shape_diff | { InteractionDiffResult :: UnmatchedResponseBodyShape ( result . clone ( ) . into_shape_diff ( shape_diff ) , ) } ) . collect ( ) } _ => vec ! [ result ] , } ) . filter ( | result | { // filter out any left-over results that aren't for outside consumoption ! matches ! ( result InteractionDiffResult UnmatchedQueryParameters ( UnmatchedQueryParameters Unobserved ( ) ) ) } ) . collect ( ) }
Compute diffs based on a spec and an interaction.
Compute diffs based on a spec and an interaction .
spec_projection
&SpecProjection
http_interaction
HttpInteraction
config
&DiffConfig