boxdot / openapi-schema

Apache License 2.0
4 stars 1 forks source link

openapi-schema build Status

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.

Example

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"
          }
        }
      }
    }
  }
}

Features

TODO

License

Contribution

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.