#openapi #swagger #schema #oas

openapi-schema

Rust structure mapped to Swagger

11 releases

0.1.10 Jun 21, 2023
0.1.9 Jun 14, 2023
0.1.5 May 25, 2023

#994 in Parser implementations

Download history 58/week @ 2024-02-15 41/week @ 2024-02-22 3/week @ 2024-02-29 4/week @ 2024-03-07 2/week @ 2024-03-14

53 downloads per month

MIT license

98KB
1K SLoC

OpenApi-Schema

Rust structure mapped to openapi

You can use this package will openapi document into rust structure

Use

cargo add openapi-schema
use openapi_schema::{from_path, Doc};

fn main() {
    let filepath = "./index.json";
    let json = from_path(filepath);
    match json {
        Ok(some_doc) => match some_doc {
            Doc::V2(swagger) => {
                println!("swagger version:{}", swagger.swagger)
            }
            Doc::V3(openapi) => {
                println!("openapi version:{}", openapi.openapi)
            }
        },
        Err(e) => {
            println!("{:?}", e)
        }
    }
}

Notice

Because some words are reserved words in rust, so will the json structure mapped to rust after structure, rust in the field name is different from some of json

Rust Json
r#type type
r#enum enum
r#in in
reference $ref

For using camelCase in json representation of the field, use snake_case in rust

Dependencies

~0.7–1.5MB
~34K SLoC