#openapi #gen #struct #build-dependencies

openapi-struct-gen

Generate rust structures from an openapi 3.0 definition

7 releases

Uses new Rust 2021

0.1.6 Aug 18, 2022
0.1.5 Aug 18, 2022

#165 in Build Utils

27 downloads per month

Apache-2.0

16KB
413 lines

This crate generates Rust structures from OpenAPI 3.0 definitions.

Example

Cargo.toml:

[dependencies]
serde = "1.0.142"
openapi-struct-gen = "*"

[build-dependencies]
openapi-struct-gen = { version = "*", features = ["build"] }

build.rs:

use openapi_struct_gen::generate;

fn main() {
    generate(
        format!(
            "{}/{}",
            std::env::var("CARGO_MANIFEST_DIR").unwrap(),
            "api.yaml"
        ),
        format!("{}/{}", std::env::var("OUT_DIR").unwrap(), "oapi.rs"),
        Some(&["Clone", "Serialize", "Deserialize"]),
        Some(&[("serde", "Serialize"), ("serde", "Deserialize")]),
        Some(&[r#"#[serde(rename_all = "camelCase")]"#]),
    )
    .unwrap();
}

code:

openapi_struct_gen::include!("oapi");

Goals

  • Generate Rust structures from Open API 3.0 definitions

Non Goals

  • Generate web servers and clients

Dependencies

~0–600KB
~12K SLoC