51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
mod auth;
|
|
pub mod util;
|
|
|
|
pub use auth::ApiKey;
|
|
use rocket::{Build, Rocket};
|
|
use rocket_okapi::{mount_endpoints_and_merged_docs, settings::OpenApiSettings};
|
|
|
|
mod prelude {
|
|
pub use super::{util, ApiKey};
|
|
pub use crate::{api_routes, Db};
|
|
pub use rocket::{
|
|
http::Status,
|
|
response::status,
|
|
serde::{json::Json, Deserialize, Serialize},
|
|
};
|
|
pub use rocket_db_pools::{sqlx, Connection};
|
|
pub use rocket_okapi::{openapi, JsonSchema};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! api_routes {
|
|
($($route:ident),* $(,)?) => {
|
|
pub fn get_routes_and_docs(
|
|
settings: &rocket_okapi::settings::OpenApiSettings
|
|
) -> (Vec<rocket::Route>, okapi::openapi3::OpenApi) {
|
|
rocket_okapi::openapi_get_routes_spec![
|
|
settings: $($route,)*
|
|
]
|
|
}
|
|
};
|
|
}
|
|
|
|
macro_rules! mount_endpoints {
|
|
($($endpoint:ident),* $(,)?) => {
|
|
$(pub mod $endpoint;)*
|
|
|
|
pub fn mount_endpoints(
|
|
mut building_rocket: Rocket<Build>,
|
|
openapi_settings: &OpenApiSettings,
|
|
) -> Rocket<Build> {
|
|
mount_endpoints_and_merged_docs! {
|
|
building_rocket, "/api".to_owned(), openapi_settings,
|
|
$(stringify!("/", $endpoint) => $endpoint::get_routes_and_docs(&openapi_settings),)*
|
|
};
|
|
building_rocket
|
|
}
|
|
};
|
|
}
|
|
|
|
mount_endpoints!(user, event);
|