This crate generates Rust structures from OpenAPI 3.0 definitions.
```toml [dependencies] serde = "1.0.142" openapi-struct-gen = "*"
[build-dependencies] openapi-struct-gen = { version = "*", features = ["build"] } ```
```rust use openapistructgen::generate;
fn main() { generate( format!( "{}/{}", std::env::var("CARGOMANIFESTDIR").unwrap(), "api.yaml" ), format!("{}/{}", std::env::var("OUTDIR").unwrap(), "oapi.rs"), Some(&["Clone", "Serialize", "Deserialize"]), Some(&[("serde", "Serialize"), ("serde", "Deserialize")]), Some(&[r#"#[skipserializingnone]"#]), Some(&[r#"#[serde(renameall = "camelCase")]"#]), ).unwrap(); } ```
The first aparameter is path to oapi schema. The second is the target output rust file. The third is derive statements. The fourth is use statements, being tuples of the path to an object and the object the fifth is annotations that are to be put before the derive statement. Sometimes such are required, like serde_with. The sixth is annotations that are to be put after the derive statement. Most annotations would be applied like that.
rust
openapi_struct_gen::include!("oapi");