|
| 1 | +# Rust API for rust-axum-array-params-test |
| 2 | + |
| 3 | +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This server was generated by the [openapi-generator] |
| 8 | +(https://openapi-generator.tech) project. By using the |
| 9 | +[OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote |
| 10 | +server, you can easily generate a server stub. |
| 11 | + |
| 12 | +To see how to make this your own, look here: [README]((https://openapi-generator.tech)) |
| 13 | + |
| 14 | +- API version: 0.0.1 |
| 15 | +- Generator version: 7.13.0-SNAPSHOT |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +This autogenerated project defines an API crate `rust-axum-array-params-test` which contains: |
| 20 | +* An `Api` trait defining the API in Rust. |
| 21 | +* Data types representing the underlying data model. |
| 22 | +* Axum router which accepts HTTP requests and invokes the appropriate `Api` method for each operation. |
| 23 | + * Request validations (path, query, body params) are included. |
| 24 | + |
| 25 | +## Using the generated library |
| 26 | + |
| 27 | +The generated library has a few optional features that can be activated through Cargo. |
| 28 | + |
| 29 | +* `server` |
| 30 | + * This defaults to enabled and creates the basic skeleton of a server implementation based on Axum. |
| 31 | + * To create the server stack you'll need to provide an implementation of the API trait to provide the server function. |
| 32 | +* `conversions` |
| 33 | + * This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types. |
| 34 | + |
| 35 | +See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`. |
| 36 | + |
| 37 | +### Example |
| 38 | + |
| 39 | +```rust |
| 40 | +struct ServerImpl { |
| 41 | + // database: sea_orm::DbConn, |
| 42 | +} |
| 43 | + |
| 44 | +#[allow(unused_variables)] |
| 45 | +#[async_trait] |
| 46 | +impl rust_axum_array_params_test::apis::default::Api for ServerImpl { |
| 47 | + // API implementation goes here |
| 48 | +} |
| 49 | + |
| 50 | +impl rust_axum_array_params_test::apis::ErrorHandler for ServerImpl {} |
| 51 | + |
| 52 | +pub async fn start_server(addr: &str) { |
| 53 | + // initialize tracing |
| 54 | + tracing_subscriber::fmt::init(); |
| 55 | + |
| 56 | + // Init Axum router |
| 57 | + let app = rust_axum_array_params_test::server::new(Arc::new(ServerImpl)); |
| 58 | + |
| 59 | + // Add layers to the router |
| 60 | + let app = app.layer(...); |
| 61 | + |
| 62 | + // Run the server with graceful shutdown |
| 63 | + let listener = TcpListener::bind(addr).await.unwrap(); |
| 64 | + axum::serve(listener, app) |
| 65 | + .with_graceful_shutdown(shutdown_signal()) |
| 66 | + .await |
| 67 | + .unwrap(); |
| 68 | +} |
| 69 | + |
| 70 | +async fn shutdown_signal() { |
| 71 | + let ctrl_c = async { |
| 72 | + signal::ctrl_c() |
| 73 | + .await |
| 74 | + .expect("failed to install Ctrl+C handler"); |
| 75 | + }; |
| 76 | + |
| 77 | + #[cfg(unix)] |
| 78 | + let terminate = async { |
| 79 | + signal::unix::signal(signal::unix::SignalKind::terminate()) |
| 80 | + .expect("failed to install signal handler") |
| 81 | + .recv() |
| 82 | + .await; |
| 83 | + }; |
| 84 | + |
| 85 | + #[cfg(not(unix))] |
| 86 | + let terminate = std::future::pending::<()>(); |
| 87 | + |
| 88 | + tokio::select! { |
| 89 | + _ = ctrl_c => {}, |
| 90 | + _ = terminate => {}, |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
0 commit comments