8 releases

new 0.2.0 Apr 18, 2024
0.1.7 Mar 26, 2024
0.1.3 Feb 20, 2024
0.1.1 Jan 30, 2024

#1 in #oas3

Download history 79/week @ 2024-01-12 184/week @ 2024-01-19 583/week @ 2024-01-26 351/week @ 2024-02-02 244/week @ 2024-02-09 399/week @ 2024-02-16 293/week @ 2024-02-23 494/week @ 2024-03-01 185/week @ 2024-03-08 239/week @ 2024-03-15 599/week @ 2024-03-22 229/week @ 2024-03-29 200/week @ 2024-04-05

1,279 downloads per month

MIT/Apache

225KB
4K SLoC

Apistos   Documentation Latest Version Build Status

An actix-web wrapper similar to paperclip to generate OAS 3.0 documentation.

Installation

[dependencies]
#schemars = "0.8"
# sadly we currently rely on a fork to fix multiple flatten for enums, related PR can be found here: https://github.com/GREsau/schemars/pull/264
schemars = { package = "apistos-schemars", version = "0.8" }
apistos = "0.2"

Usage example

Wrap your regular actix-web app using apistos types.

Most of these types are drop-in types for actix-web one's.

use actix_web::{App, HttpServer};
use actix_web::web::Json;
use apistos::actix::CreatedJson;
use apistos::api_operation;
use apistos::ApiComponent;
use apistos::ApiErrorComponent;
use apistos::spec::Spec;
use apistos::web::{post, resource, scope};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::net::Ipv4Addr;

#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, ApiComponent)]
pub struct Test {
  pub test: String
}

#[derive(Serialize, Deserialize, Clone, ApiErrorComponent)]
#[openapi_error(
  status(code = 403),
  status(code = 404),
  status(code = 405, description = "Invalid input"),
  status(code = 409)
)]
pub enum ErrorResponse {
  MethodNotAllowed(String),
  NotFound(String),
  Conflict(String),
  Unauthorized(String),
}

#[api_operation(
  tag = "pet",
  summary = "Add a new pet to the store",
  description = r###"Add a new pet to the store
    Plop"###,
  error_code = 405
)]
pub(crate) async fn test(
  body: Json<Test>,
) -> Result<CreatedJson<Test>, ErrorResponse> {
  Ok(CreatedJson(body.0))
}

#[actix_web::main]
async fn main() -> Result<(), impl Error> {
  HttpServer::new(move || {
    let spec = Spec {
      info: Info {
        title: "An API".to_string(),
        version: "1.0.0".to_string(),
        ..Default::default()
      },
      ..Default::default()
    };

    App::new()
      .document(spec)
      .wrap(Logger::default())
      .service(scope("/test")
        .service(
          resource("")
            .route(post().to(test))
        )
      )
      .build("/openapi.json")
    })
    .bind((Ipv4Addr::UNSPECIFIED, 8080))?
    .run()
    .await
}

For a complete example, see the sample petstore.

Feature flags

name description extra dependencies
chrono Enables documenting types from chrono chrono
multipart Enables documenting types from actix-multipart actix-multipart
rust_decimal Enables documenting types from rust_decimal rust_decimal =
uuid Enables documenting types from uuid uuid
url Enables documenting types from url url
extras Enables chrono, multipart, rust_decimal, uuid and url features All from previous features

About us

apistos is provided by Netwo.

We use this crate for our internal needs and therefore are committed to its maintenance, however we cannot provide any additional guaranty. Use it at your own risks.

While we won't invest in any feature we don't need, we are open to accept any pull request you might propose.

We are a France based full-remote company operating in the telecom industry. If you are interested in learning more, feel free to visit our career page.

Dependencies

~21–36MB
~637K SLoC