9 releases

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

#306 in Web programming

Download history 98/week @ 2024-01-13 208/week @ 2024-01-20 631/week @ 2024-01-27 292/week @ 2024-02-03 277/week @ 2024-02-10 396/week @ 2024-02-17 361/week @ 2024-02-24 400/week @ 2024-03-02 189/week @ 2024-03-09 259/week @ 2024-03-16 605/week @ 2024-03-23 168/week @ 2024-03-30 268/week @ 2024-04-06 454/week @ 2024-04-13 256/week @ 2024-04-20

1,212 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
~646K SLoC