reactive_graph/server/json_schema/
mod.rs

1use crate::server::json_schema::commands::InstancesCommands;
2use crate::server::json_schema::commands::JsonSchemaCommands;
3use crate::server::json_schema::commands::TypesCommands;
4use reactive_graph_instance_system_json_schema::schema_entity_instances;
5use reactive_graph_instance_system_json_schema::schema_flow_instances;
6use reactive_graph_instance_system_json_schema::schema_relation_instances;
7use reactive_graph_type_system_json_schema::schema_components;
8use reactive_graph_type_system_json_schema::schema_entity_types;
9use reactive_graph_type_system_json_schema::schema_flow_types;
10use reactive_graph_type_system_json_schema::schema_relation_types;
11use std::process::exit;
12
13pub mod args;
14pub mod commands;
15
16pub async fn print_json_schema_and_exit(commands: &JsonSchemaCommands) {
17    let json_schema = match commands {
18        JsonSchemaCommands::Types(args) => match args.commands {
19            TypesCommands::Components => schema_components(),
20            TypesCommands::Entities => schema_entity_types(),
21            TypesCommands::Relations => schema_relation_types(),
22            TypesCommands::Flows => schema_flow_types(),
23        },
24        JsonSchemaCommands::Instances(args) => match args.commands {
25            InstancesCommands::Entities => schema_entity_instances(),
26            InstancesCommands::Relations => schema_relation_instances(),
27            InstancesCommands::Flows => schema_flow_instances(),
28        },
29    };
30    match serde_json::to_string_pretty(&json_schema.to_value()) {
31        Ok(json_schema) => {
32            println!("{json_schema}");
33            exit(0);
34        }
35        Err(_) => {
36            exit(1);
37        }
38    }
39}