diff --git a/Cargo.lock b/Cargo.lock index b793a35a..af1498f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1703,6 +1703,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", + "serde_yaml", "strum", "testcontainers-modules", "tokio", @@ -3278,6 +3279,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha-1" version = "0.10.1" @@ -4012,6 +4026,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.7.1" diff --git a/integrationos-api/Cargo.toml b/integrationos-api/Cargo.toml index 936f31f2..d28c1183 100644 --- a/integrationos-api/Cargo.toml +++ b/integrationos-api/Cargo.toml @@ -42,6 +42,7 @@ tower_governor = "0.3.2" tracing-subscriber.workspace = true tracing.workspace = true validator.workspace = true +serde_yaml = "0.9.34" [dev-dependencies] testcontainers-modules = { workspace = true, features = ["mongo", "redis"] } diff --git a/integrationos-api/src/endpoints/openapi.rs b/integrationos-api/src/endpoints/openapi.rs index c7b3679b..58672386 100644 --- a/integrationos-api/src/endpoints/openapi.rs +++ b/integrationos-api/src/endpoints/openapi.rs @@ -126,6 +126,30 @@ pub async fn refresh_openapi( )) } +#[tracing::instrument(name = "Get OpenAPI schema YAML", skip(state))] +pub async fn get_openapi_yaml( + state: State>, +) -> Result<(StatusCode, Vec), ApiError> { + let spec = get_openapi(state).await; + + match spec { + Ok((status_code, Json(spec))) => { + let try_yaml: serde_yaml::Value = serde_yaml::to_value(spec).map_err(|e| { + error!("Could not serialize openapi schema to yaml: {:?}", e); + internal_server_error!() + })?; + + let text = serde_yaml::to_string(&try_yaml).map_err(|e| { + error!("Could not serialize openapi schema to yaml: {:?}", e); + internal_server_error!() + })?; + + Ok((status_code, text.into_bytes())) + } + Err(e) => Err(e), + } +} + #[tracing::instrument(name = "Get OpenAPI schema", skip(state))] pub async fn get_openapi( state: State>, diff --git a/integrationos-api/src/routes/public.rs b/integrationos-api/src/routes/public.rs index da52087e..dac0cdd9 100644 --- a/integrationos-api/src/routes/public.rs +++ b/integrationos-api/src/routes/public.rs @@ -39,6 +39,7 @@ pub fn get_router(state: &Arc) -> Router> { >), ) .route("/openapi", get(openapi::get_openapi)) + .route("/openapi/yaml", get(openapi::get_openapi_yaml)) .route( "/connection-data/models/:platform_name", get(connection_model_schema::get_platform_models),