@@ -7,9 +7,13 @@ use actix_multipart::form::tempfile::TempFileConfig;
77use actix_web:: middleware:: Logger ;
88use actix_web:: { web, App , HttpServer } ;
99
10+ use openapi:: ApiDoc ;
1011use openubl_api:: system:: InnerSystem ;
1112use openubl_common:: config:: Database ;
1213use openubl_storage:: StorageSystem ;
14+ use utoipa:: OpenApi ;
15+ use utoipa_actix_web:: AppExt ;
16+ use utoipa_swagger_ui:: SwaggerUi ;
1317
1418use crate :: server:: credentials:: {
1519 create_credentials, delete_credentials, get_credentials, list_credentials, update_credentials,
@@ -20,6 +24,7 @@ use actix_web_static_files::{deps::static_files::Resource, ResourceFiles};
2024use openubl_ui:: { openubl_ui, UI } ;
2125
2226mod dto;
27+ pub mod openapi;
2328pub mod server;
2429
2530pub struct UiResources {
@@ -89,11 +94,25 @@ impl ServerRun {
8994 let app_state = Arc :: new ( AppState { system, storage } ) ;
9095
9196 HttpServer :: new ( move || {
92- App :: new ( )
93- . app_data ( web:: Data :: from ( app_state. clone ( ) ) )
97+ let ( app, api) = App :: new ( )
9498 . wrap ( Logger :: default ( ) )
99+ . into_utoipa_app ( )
100+ //
101+ . openapi ( ApiDoc :: openapi ( ) )
102+ //
103+ . app_data ( web:: Data :: from ( app_state. clone ( ) ) )
95104 . app_data ( TempFileConfig :: default ( ) )
96- . configure ( configure)
105+ // q
106+ . service ( utoipa_actix_web:: scope ( "/q" ) . configure ( configure_q) )
107+ // API
108+ . service ( utoipa_actix_web:: scope ( "/api" ) . configure ( configure_api) )
109+ . split_for_parts ( ) ;
110+
111+ app
112+ // Swagger
113+ . service ( SwaggerUi :: new ( "/swagger-ui/{_:.*}" ) . url ( "/openapi.json" , api) )
114+ . service ( web:: redirect ( "/swagger-ui" , "/swagger-ui/" ) )
115+ // UI
97116 . service ( ResourceFiles :: new ( "/" , ui. resources ( ) ) . resolve_not_found_to ( "" ) )
98117 } )
99118 . bind ( self . bind_addr ) ?
@@ -109,11 +128,13 @@ pub struct AppState {
109128 pub storage : StorageSystem ,
110129}
111130
112- pub fn configure ( config : & mut web :: ServiceConfig ) {
131+ pub fn configure_q ( config : & mut utoipa_actix_web :: service_config :: ServiceConfig ) {
113132 // Health
114133 config. service ( health:: liveness) ;
115134 config. service ( health:: readiness) ;
135+ }
116136
137+ pub fn configure_api ( config : & mut utoipa_actix_web:: service_config:: ServiceConfig ) {
117138 // Documents
118139 config. service ( list_documents) ;
119140 config. service ( get_document_file) ;
0 commit comments