docs_renderer/
main.rs

1mod renderer;
2
3use std::collections::HashMap;
4
5use anyhow::{Context, Result};
6use tracing::debug;
7use vector_config::schema::parser::{component::ComponentSchema, query::SchemaQuerier};
8use vector_config_common::constants::{self, ComponentType};
9
10use crate::renderer::SchemaRenderer;
11
12fn main() -> Result<()> {
13    let querier = SchemaQuerier::from_schema("/tmp/vector-config-schema.json")
14        .context("Failed to create querier from given schema file path.")?;
15
16    let base_component_types = &[
17        ComponentType::Source,
18        ComponentType::Transform,
19        ComponentType::Sink,
20    ];
21    for base_component_type in base_component_types {
22        // Find the base component schema for the component type itself, which is analogous to
23        // `SourceOuter`, `SinkOuter`, etc. We render the schema for that separately as it's meant
24        // to be common across components of the same type, etc.
25        let base_component_schema = querier
26            .query()
27            .with_custom_attribute_kv(
28                constants::DOCS_META_COMPONENT_BASE_TYPE,
29                base_component_type,
30            )
31            .run_single()?;
32
33        debug!(
34            "Got base component schema for component type '{}'.",
35            base_component_type.as_str()
36        );
37
38        // Find all component schemas of the same component type.
39        let maybe_component_schemas = querier
40            .query()
41            .with_custom_attribute_kv(constants::DOCS_META_COMPONENT_TYPE, base_component_type)
42            .run()
43            .into_iter()
44            .map(ComponentSchema::try_from)
45            .collect::<Result<Vec<_>, _>>()?;
46
47        debug!(
48            "Found {} component schema(s) for component type '{}'.",
49            maybe_component_schemas.len(),
50            base_component_type.as_str()
51        );
52
53        let mut rendered_component_schemas = HashMap::new();
54
55        // Render the base component schema.
56        let base_component_schema_renderer = SchemaRenderer::new(&querier, base_component_schema);
57        let rendered_base_component_schema =
58            base_component_schema_renderer.render().context(format!(
59                "Failed to render the base component schema for component type '{}'.",
60                base_component_type.as_str()
61            ))?;
62        rendered_component_schemas.insert(
63            format!("base/{}", base_component_type.as_str()),
64            rendered_base_component_schema,
65        );
66
67        // Render each of the component schemas for this component type.
68        for component_schema in maybe_component_schemas {
69            let component_name = component_schema.component_name().to_string();
70            let component_schema_renderer = SchemaRenderer::new(&querier, component_schema);
71            let rendered_component_schema = component_schema_renderer.render().context(format!(
72                "Failed to render the '{component_name}' component schema."
73            ))?;
74            rendered_component_schemas.insert(
75                format!("{}s/base/{}", base_component_type.as_str(), component_name),
76                rendered_component_schema,
77            );
78        }
79    }
80
81    Ok(())
82}