Skip to content

jakobhellermann/axum_openapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WIP crate for auto-generating openapi descriptions for web services written using the axum framework.

Example usage:

use axum::prelude::*;
use std::net::SocketAddr;

use axum_openapi::prelude::*;
use axum_openapi::{openapi_json_endpoint, openapi_yaml_endpoint};

#[tokio::main]
async fn main() {
    let app = route("/pets", get(find_pets).post(add_pet))
        .route("/pets/:id", get(find_pet_by_id).delete(delete_pet));
    let openapi = app.openapi();

    let app = app
        .route("/openapi.yaml", openapi_yaml_endpoint(openapi.clone()))
        .route("/openapi.json", openapi_json_endpoint(openapi));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    hyper::server::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

async fn find_pets(/* */) { /* */ }
async fn add_pet(/* */) { /* */ }
async fn find_pet_by_id(/* */) { /* */ }
async fn delete_pet(/* */) { /* */ }

See the full example at ./examples/petstore.rs.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages