armature-openapi
OpenAPI/Swagger documentation for the Armature framework.
Features
- Programmatic Builder - Build OpenAPI 3.0 specs by hand with a fluent builder API
- Swagger UI - HTML response helper for interactive API documentation (loads UI assets from a CDN; requires internet access, not self-contained)
- Export - JSON/YAML spec export
There is currently no route introspection, handler type inference, or
request-validation support in this crate — specs are assembled entirely by
hand via OpenApiBuilder.
Installation
[]
= "0.1"
Quick Start
use ;
// Build the spec by hand with the fluent builder.
let spec = new
.description
.server
.build;
// Wrap it in a SwaggerConfig to serve it.
let config = new.with_title;
// `swagger_ui_response(&config)` returns an `HttpResponse` rendering the Swagger UI HTML page.
// `spec_json_response(&config)` returns an `HttpResponse` serving the raw spec as JSON.
let ui_response = swagger_ui_response.unwrap;
let json_response = spec_json_response.unwrap;
assert_eq!;
assert_eq!;
Wire these into your router as you would any other handler, e.g. serving
ui_response at GET /api-docs and json_response at GET /openapi.json.
Adding Paths and Operations
use ;
use HashMap;
let list_users = new
.summary
.operation_id
.response
.build;
let path_item = new.get.build;
let mut spec = new.build;
spec.paths.insert;
assert!;
Schemas
Schemas are also built by hand, either with the raw Schema struct or the
helper functions in armature_openapi::builder (string_schema,
integer_schema, object_schema, array_schema, ref_schema, ...):
use ;
use HashMap;
let mut properties = new;
properties.insert;
properties.insert;
let create_user_schema = object_schema;
assert_eq!;
Authentication
use ;
let spec = new
.add_bearer_auth
.add_api_key_auth
.build;
assert!;
Supported security schemes: HTTP (e.g. Bearer), API Key, OAuth2, and OpenID
Connect (SecurityScheme::OpenIdConnect).
License
MIT OR Apache-2.0