diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
commit | c622eab39ac7dd9f794b5d60eb937e29c9b3bd6e (patch) | |
tree | a75067a661250a4ed74096929083948f65c01fdb /src/doc.rs | |
parent | 5891af7e8c1411029fe1ad9c6d3182f88bcf3dfd (diff) |
add api documentation
Diffstat (limited to 'src/doc.rs')
-rw-r--r-- | src/doc.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/doc.rs b/src/doc.rs new file mode 100644 index 0000000..2d5e168 --- /dev/null +++ b/src/doc.rs @@ -0,0 +1,56 @@ +use utoipa::{ + openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, + Modify, OpenApi, +}; +use crate::auth; + +use crate::api; + +pub fn get_openapi() -> utoipa::openapi::OpenApi { + /* utoipa setup */ + #[derive(OpenApi)] + #[openapi( + paths( + api::album::post_album, + api::album::put_album, + api::album::get_album, + api::album::delete_album, + api::artist::post_artist, + api::artist::put_artist, + api::artist::get_artist, + api::artist::delete_artist, + api::song::post_song, + api::song::put_song, + api::song::get_song, + api::song::delete_song, + api::search_results::search_results, + auth::register, + auth::login, + auth::delete_user, + ), + components( + schemas( + ) + ), + modifiers(&SecurityAddon) + )] + struct ApiDoc; + + struct SecurityAddon; + impl Modify for SecurityAddon { + fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) { + let components = openapi.components.as_mut().unwrap(); + components.add_security_scheme( + "bearer_auth", + SecurityScheme::Http( + HttpBuilder::new() + .scheme(HttpAuthScheme::Bearer) + .bearer_format("JWT") + .build(), + ), + ); + } + } + + return ApiDoc::openapi(); +} |