Skip to content

Commit

Permalink
feature: implementing yaml openapi spec (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored May 23, 2024
1 parent 7880d7a commit f5eacdb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integrationos-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
24 changes: 24 additions & 0 deletions integrationos-api/src/endpoints/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<AppState>>,
) -> Result<(StatusCode, Vec<u8>), 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<Arc<AppState>>,
Expand Down
1 change: 1 addition & 0 deletions integrationos-api/src/routes/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn get_router(state: &Arc<AppState>) -> Router<Arc<AppState>> {
>),
)
.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),
Expand Down

0 comments on commit f5eacdb

Please sign in to comment.