Add strict mode and defaults for GET tagged schedules
This commit is contained in:
parent
f9ad8f9399
commit
3c70ae1da3
4 changed files with 41 additions and 75 deletions
src
22
src/main.rs
22
src/main.rs
|
@ -4,11 +4,12 @@ use actix::{Actor, Arbiter};
|
|||
use actix_cors::Cors;
|
||||
use actix_web::middleware::TrailingSlash;
|
||||
use actix_web::{middleware, web, App, HttpServer};
|
||||
use serde_json::Value;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
use emgauwa_common::db::DbController;
|
||||
use emgauwa_common::errors::EmgauwaError;
|
||||
use emgauwa_common::utils::{drop_privileges, init_logging};
|
||||
use serde_json::json;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
use crate::app_state::AppState;
|
||||
|
||||
|
@ -46,6 +47,9 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
AppState::new(app_state_pool)
|
||||
});
|
||||
|
||||
let api_v1_json: Value =
|
||||
serde_json::from_str(include_str!("../api.v1.json")).map_err(EmgauwaError::from)?;
|
||||
|
||||
log::info!(
|
||||
"Starting server on {}:{}",
|
||||
settings.server.host,
|
||||
|
@ -63,18 +67,6 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
}),
|
||||
};
|
||||
|
||||
let api_default = json!({
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "0.0.0",
|
||||
"title": "Failed to load API documentation",
|
||||
}
|
||||
});
|
||||
|
||||
let api_v1_json =
|
||||
serde_json::from_str(include_str!("../api.v1.json")).unwrap_or(api_default.clone());
|
||||
|
||||
|
||||
App::new()
|
||||
.wrap(cors)
|
||||
.wrap(middleware::Logger::default())
|
||||
|
@ -83,7 +75,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
.app_data(web::Data::new(app_state.clone()))
|
||||
.service(
|
||||
SwaggerUi::new("/api/docs/{_:.*}")
|
||||
.external_urls_from_iter_unchecked([("/api/v1.json", api_v1_json)]),
|
||||
.external_urls_from_iter_unchecked([("/api/v1.json", api_v1_json.clone())]),
|
||||
)
|
||||
.service(web::redirect("/api/docs", "/api/docs/"))
|
||||
.service(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue