Closed afidegnum closed 1 month ago
For such case you need to serve it through an enpoint as you would do with any other content. And also with that you do not need the utoipa-swagger-ui
library to be there.
async fn get_api_doc(....) -> Json<utoipa::openapi::OpenApi> {
let doc = // .... load the doc somewhere or from fn arguments
Json(doc)
}
Can you please give an example? i'm a bit confused.
Sure,
For example if you take a look at the warp
example you can find that the apidoc.json is served via regular http endpoint handler (whatever handles the incoming requests). https://github.com/juhaku/utoipa/blob/489ddd663051a578e9285f5f4b5d87c0f626d6c0/examples/todo-warp/src/main.rs#L46-L48
Or with actix_web
same example might look something like this:
#[get("/api-docs/openapi.json")]
async fn get_api_doc(apidoc: Data<OpenApi>) -> impl Responder {
let doc = apidoc.lock().unwrap();
HttpResponse::Ok().json(doc)
}
If you want to return only the openapi
schema then you need to create a custom endpoint for it according to the framework of your choise. You cannot use the SwaggerUi
type without exposing the Swagger UI to the public.
Does this help? Or have I understood your question totally wrong?
Thanks a lot.
Closed due inactivity.
With
swagger-ui
I would like to return only the openapi schema without the UI,the following code still returns the ui interface.
SwaggerUi::new("").url("/api-docs/openapi.json", openapi.clone()),