OpenAPI 3.0 Schema generation library for Rust types.
The implementation is experimental. For now, we support only features needed to implement a simple
spec generation from an actix-web
application (cf. https://github.com/actix/actix-web/issues/310).
If you are interested in the library and want to use it in your project, feel free to extend the
supported types.
use openapi_schema::OpenapiSchema;
/// A tag for a pet
#[derive(OpenapiSchema)]
pub struct Tag {
pub id: u64,
pub name: Option<String>,
}
fn main() {
let mut spec = openapi::v3_0::Spec::default();
Tag::generate_schema(&mut spec);
println!("{}", serde_json::to_string_pretty(&spec).unwrap());
}
The above example generates the following schema:
{
"openapi": "",
"info": {
"title": "",
"version": ""
},
"paths": {},
"components": {
"schemas": {
"Tag": {
"description": "A tag for a pet",
"required": [
"id"
],
"properties": {
"id": {
"type": "number",
"format": "int64",
"minimum": 0
},
"name": {
"type": "string"
}
}
}
}
}
}
i64
, u64
, i32
, u32
, bool
, String
Option<T>
Vec<T>
title
and description
of the schema.description
of the property.serde(flatten)
.TODO
serde(rename)
.serde(default)
.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this document by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.