1use super::content::ContentDiff;
2use crate::openapi::{ReferenceOr, Response};
3use serde::Serialize;
4
5#[derive(Debug, Serialize)]
6pub struct ResponseDiff {
7 pub content: Option<ContentDiff>,
8}
9
10impl ResponseDiff {
11 pub fn has_changes(&self) -> bool {
12 self.content.is_some()
13 }
14
15 pub fn from_responses(base: &ReferenceOr<Response>, head: &ReferenceOr<Response>) -> Self {
16 let base_response = match &base {
17 ReferenceOr::Item(i) => i,
18 ReferenceOr::Reference { reference: _ } => {
19 panic!("$ref not supported yet");
20 }
21 };
22
23 let head_response = match &head {
24 ReferenceOr::Item(i) => i,
25 ReferenceOr::Reference { reference: _ } => {
26 panic!("$ref not supported yet");
27 }
28 };
29
30 let content_diff =
31 ContentDiff::from_content(&base_response.content, &head_response.content);
32
33 if content_diff.has_changes() {
34 Self {
35 content: Some(content_diff),
36 }
37 } else {
38 Self { content: None }
39 }
40 }
41}