use oparlint_linting::{LintSuite, LintingResult};
use oparlint_lints::json::{BodyIsJsonLint, BodyIsJsonObjectLint};
use reqwest::Response;
use serde_json::{Map, Value};
#[derive(Debug)]
pub struct HttpJsonObjectSuite {
response: Response,
}
impl HttpJsonObjectSuite {
pub fn new(response: Response) -> Self {
Self { response }
}
}
#[async_trait::async_trait]
impl LintSuite for HttpJsonObjectSuite {
type Output = Map<String, Value>;
fn identifier(&self) -> String {
"json-object".into()
}
fn title(&self) -> String {
"HTTP response is a proper JSON object".into()
}
async fn execute<L: oparlint_linting::Linter + Send>(
self,
linter: &mut L,
) -> LintingResult<Self::Output> {
let deserialized = self.response.json::<Value>().await;
let json = linter.execute_lint(BodyIsJsonLint::new(deserialized))?;
linter.execute_lint(BodyIsJsonObjectLint::new(json))
}
}