Compare commits
3 Commits
8415a4e503
...
2c807d62bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c807d62bc | ||
|
|
2efaa86440 | ||
|
|
ea5a23ac23 |
5
.github/workflows/dependency-check.yml
vendored
5
.github/workflows/dependency-check.yml
vendored
@@ -1,9 +1,6 @@
|
|||||||
name: Dependency Check
|
name: Dependency Check
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
|
||||||
# Run every Monday at 9:00 AM UTC
|
|
||||||
- cron: "0 9 * * 1"
|
|
||||||
workflow_dispatch: # Allow manual triggering
|
workflow_dispatch: # Allow manual triggering
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -222,7 +219,7 @@ jobs:
|
|||||||
run: >-
|
run: >-
|
||||||
tea login add
|
tea login add
|
||||||
-u "${{ github.server_url }}"
|
-u "${{ github.server_url }}"
|
||||||
-t "${{ secrets.GITHUB_TOKEN }}"
|
-t "${{ secrets.REPO_WRITE_TOKEN }}"
|
||||||
|
|
||||||
- name: Create Pull Request with dependency updates
|
- name: Create Pull Request with dependency updates
|
||||||
if: steps.upgrade.outputs.has_updates == 'true'
|
if: steps.upgrade.outputs.has_updates == 'true'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ aide = { version = "0.16.0-alpha.1", features = [
|
|||||||
"axum",
|
"axum",
|
||||||
"axum-json",
|
"axum-json",
|
||||||
"axum-query",
|
"axum-query",
|
||||||
|
"swagger"
|
||||||
] }
|
] }
|
||||||
{% endif %}
|
{% endif %}
|
||||||
anyhow = "1.0.101"
|
anyhow = "1.0.101"
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ use axum_app_wrapper::App;
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod routes;
|
||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
pub async fn create_app() -> anyhow::Result<(axum::Router, AppConfig, impl Future + Send)> {
|
pub async fn create_app() -> anyhow::Result<(axum::Router, AppConfig, impl Future + Send)> {
|
||||||
let (router, state, on_shutdown) = App::new().register(config::plugin()).init().await?;
|
let (router, state, on_shutdown) = App::new()
|
||||||
|
.register(config::plugin()) // Extract configuration and add to state
|
||||||
|
.register(routes::plugin()) // Add API routes
|
||||||
|
.init()
|
||||||
|
.await?;
|
||||||
let app_config = state.config.to_owned();
|
let app_config = state.config.to_owned();
|
||||||
|
|
||||||
Ok((router.with_state(state), app_config, on_shutdown))
|
Ok((router.with_state(state), app_config, on_shutdown))
|
||||||
|
|||||||
54
src/routes/hello.rs
Normal file
54
src/routes/hello.rs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{% if include_aide %}
|
||||||
|
use axum::extract::{Json, Query};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
|
{% endif %}
|
||||||
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
{% if include_aide == false %}
|
||||||
|
pub fn routes() -> axum::Router<AppState> {
|
||||||
|
axum::Router::new()
|
||||||
|
.route("/", axum::routing::get(hello_handler))
|
||||||
|
.route("/", axum::routing::post(post_handler))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn hello_handler() -> String {
|
||||||
|
"Hello, World!".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post_handler() -> String {
|
||||||
|
"Post handler!".to_string()
|
||||||
|
}
|
||||||
|
{% else %}
|
||||||
|
pub fn routes() -> aide::axum::ApiRouter<AppState> {
|
||||||
|
aide::axum::ApiRouter::new()
|
||||||
|
.api_route(
|
||||||
|
"/",
|
||||||
|
aide::axum::routing::get_with(hello_handler, |op| op.summary("Greet user")),
|
||||||
|
)
|
||||||
|
.api_route(
|
||||||
|
"/",
|
||||||
|
aide::axum::routing::post_with(post_handler, |op| op.summary("Relay message")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn hello_handler(Query(query): Query<HelloQuery>) -> String {
|
||||||
|
format!("Hello, {}!", query.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post_handler(Json(body): Json<PostBody>) -> String {
|
||||||
|
format!("Received message: {}", body.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, JsonSchema)]
|
||||||
|
struct HelloQuery {
|
||||||
|
/// The name of the person to greet
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, JsonSchema)]
|
||||||
|
struct PostBody {
|
||||||
|
/// The message to relay
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
47
src/routes/mod.rs
Normal file
47
src/routes/mod.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use axum_app_wrapper::AdHocPlugin;
|
||||||
|
|
||||||
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
pub mod hello;
|
||||||
|
|
||||||
|
/// Adds all API routes to the server under `/api`
|
||||||
|
pub fn plugin() -> AdHocPlugin<AppState> {
|
||||||
|
AdHocPlugin::new().on_setup(|router, _state| {
|
||||||
|
{% if include_aide == false %}
|
||||||
|
let api_routes = axum::Router::new().nest("/hello", hello::routes());
|
||||||
|
|
||||||
|
Ok(router.nest("/api", api_routes))
|
||||||
|
{% else %}
|
||||||
|
// Build API routes
|
||||||
|
let api_router = aide::axum::ApiRouter::new().nest("/hello", hello::routes());
|
||||||
|
|
||||||
|
// OpenAPI configuration
|
||||||
|
let mut openapi = aide::openapi::OpenApi {
|
||||||
|
info: aide::openapi::Info {
|
||||||
|
title: "{{project-name}}".to_string(),
|
||||||
|
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||||
|
description: Some("{{project-description}}".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
servers: vec![aide::openapi::Server {
|
||||||
|
url: "/api".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add API routes to the router under `/api` and also merge them into the OpenAPI docs
|
||||||
|
let router = router.nest("/api", api_router.finish_api(&mut openapi));
|
||||||
|
|
||||||
|
// Add OpenAPI documentation routes
|
||||||
|
let openapi_json = serde_json::to_string_pretty(&openapi).unwrap();
|
||||||
|
let openapi_route = axum::routing::get(|| async move { openapi_json });
|
||||||
|
let swagger_route = aide::swagger::Swagger::new("/api/openapi.json").axum_route();
|
||||||
|
let router = router
|
||||||
|
.route("/api/openapi.json", openapi_route)
|
||||||
|
.route("/api/docs", swagger_route.into());
|
||||||
|
|
||||||
|
Ok(router)
|
||||||
|
{% endif %}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user