Proto selection UI/models

This commit is contained in:
Gregory Schier
2024-02-06 12:29:23 -08:00
parent 8309c19167
commit 1293870e11
28 changed files with 382 additions and 154 deletions

View File

@@ -1,8 +1,5 @@
use prost_reflect::SerializeOptions;
use serde::{Deserialize, Serialize};
use tonic::transport::Uri;
use crate::proto::fill_pool;
mod codec;
mod json_schema;
@@ -28,31 +25,3 @@ pub struct MethodDefinition {
pub client_streaming: bool,
pub server_streaming: bool,
}
pub async fn reflect(uri: &Uri) -> Result<Vec<ServiceDefinition>, String> {
let (pool, _) = fill_pool(uri).await?;
Ok(pool
.services()
.map(|s| {
let mut def = ServiceDefinition {
name: s.full_name().to_string(),
methods: vec![],
};
for method in s.methods() {
let input_message = method.input();
def.methods.push(MethodDefinition {
name: method.name().to_string(),
server_streaming: method.is_server_streaming(),
client_streaming: method.is_client_streaming(),
schema: serde_json::to_string_pretty(&json_schema::message_to_json_schema(
&pool,
input_message,
))
.unwrap(),
})
}
def
})
.collect::<Vec<_>>())
}