next-web-api-doc 0.1.0

Api Doc
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented4 out of 10 items with examples
  • Size
  • Source code size: 16.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 36.11 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 44s Average build duration of successful builds.
  • all releases: 44s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • yuenxillar/next-web
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yuenxillar

Api Doc

A crate for integrating utoipa with next-web Framework for automatic OpenAPI/Swagger documentation generation.

The rules are consistent with utoipa

WARNING

Due to the limitations of the utoipa, you must add utoipa to your Cargo.toml

cargo add utoipa

Examples

use next_web::{
    api_doc, application::Application, async_trait, extract::find_singleton::FindSingleton,
    post_mapping, request_mapping,
};
use next_web_core::{context::properties::ApplicationProperties, ApplicationContext};
use utoipa::openapi::OpenApi;

#[derive(Default, Clone)]
pub struct TestApplication;

#[async_trait]
impl Application for TestApplication {
    type ErrorSolve = ();

    async fn init_middleware(
        &self,
        _ctx: &mut ApplicationContext,
        _properties: &ApplicationProperties,
    ) {
    }
}

#[api_doc(
    responses(
        (status = 200, description = "JSON file", body = ())
    )
)]
#[request_mapping(method = "GET", path = "/test")]
async fn openapi(FindSingleton(open_api): FindSingleton<OpenApi>) -> String {
    open_api.to_pretty_json().unwrap()
}

#[api_doc]
#[post_mapping(path = "/test1")]
async fn test() -> String {
    String::from("Hello world!")
}

#[tokio::main]
async fn main() {
    TestApplication::run().await;
}