schema_registry_api/service/
compatibility.rs

1use crate::{CompatibilityResult, RegisterSchema, SchemaRegistryError, SchemaVersion, SubjectName};
2
3use super::SchemaRegistry;
4
5/// The compatibility client
6#[derive(Debug)]
7pub struct CompatibilityClient<'sr> {
8    pub(super) sr: &'sr SchemaRegistry,
9}
10
11impl CompatibilityClient<'_> {
12    /// Test input schema against a particular version of a subject’s schema for compatibility.
13    ///
14    /// # Errors
15    ///
16    /// Fail if we cannot send the query
17    /// Fail if the schema registry return an error
18    #[tracing::instrument(skip(self))]
19    pub async fn check_version(
20        &self,
21        subject: &SubjectName,
22        version: SchemaVersion,
23        schema: &RegisterSchema,
24        verbose: Option<bool>,
25    ) -> Result<CompatibilityResult, SchemaRegistryError> {
26        let path = format!("compatibility/subjects/{subject}/versions/{version}");
27        let mut url = self.sr.base_url.join(&path)?;
28        if let Some(verbose) = verbose {
29            let query = format!("verbose={verbose}");
30            url.set_query(Some(&query));
31        }
32        self.sr.post(url, schema).await
33    }
34
35    /// Perform a compatibility check on the schema against one or more versions in the subject,
36    /// depending on how the compatibility is set.
37    ///
38    /// # Errors
39    ///
40    /// Fail if we cannot send the query
41    /// Fail if the schema registry return an error
42    #[tracing::instrument(skip(self))]
43    pub async fn check_versions(
44        &self,
45        subject: &SubjectName,
46        schema: &RegisterSchema,
47        verbose: Option<bool>,
48    ) -> Result<CompatibilityResult, SchemaRegistryError> {
49        let path = format!("compatibility/subjects/{subject}/versions");
50        let mut url = self.sr.base_url.join(&path)?;
51        if let Some(verbose) = verbose {
52            let query = format!("verbose={verbose}");
53            url.set_query(Some(&query));
54        }
55        self.sr.post(url, schema).await
56    }
57}