schema_registry_cli/command/
schema.rs

1use schema_registry_api::{Schema, SchemaId, SchemaRegistry, SubjectName};
2
3use crate::{GetSchema, Result, SchemaRegistrySettings};
4
5/// Get schema from id
6///
7/// # Errors
8///
9/// Fail if the API fail
10pub async fn get_schema(
11    client_settings: SchemaRegistrySettings,
12    id: SchemaId,
13    subject: Option<&SubjectName>,
14) -> Result<Option<Schema>> {
15    let client = SchemaRegistry::try_from(client_settings)?;
16    let result = client.schema().get(id, subject).await?;
17    Ok(result)
18}
19
20pub(crate) async fn display_get_schema(get_schema: GetSchema) -> Result<()> {
21    let GetSchema {
22        schema_registry,
23        id,
24        subject,
25    } = get_schema;
26    let schema = self::get_schema(schema_registry, id, subject.as_ref()).await?;
27
28    // Display
29    if let Some(schema) = schema {
30        println!("{}", schema.schema);
31    } else {
32        println!("No schema with id {id} found");
33    }
34
35    Ok(())
36}