Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: implementing yaml openapi spec #44

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading