Skip to main content

oxapi

Attribute Macro oxapi 

Source
#[oxapi]
Expand description

Main attribute macro for generating server stubs from OpenAPI specs.

§Example (single trait)

#[oxapi::oxapi(axum, "spec.json")]
trait MyServer {
    #[oxapi(map)]
    fn map_routes(router: Router) -> Router;

    #[oxapi(get, "/users")]
    async fn get_users(state: State<AppState>, query: Query<_>);
}

§Example (module with multiple traits)

#[oxapi::oxapi(axum, "spec.json")]
mod my_api {
    trait PetService {
        #[oxapi(map)]
        fn map_routes(router: Router<PetState>) -> Router<PetState>;

        #[oxapi(get, "/pet/{petId}")]
        async fn get_pet(state: State<PetState>, pet_id: Path<_>);
    }

    trait StoreService {
        #[oxapi(map)]
        fn map_routes(router: Router<StoreState>) -> Router<StoreState>;

        #[oxapi(get, "/store/inventory")]
        async fn get_inventory(state: State<StoreState>);
    }
}