Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/denganjia/openapi-schema
Rust structure mapped to Swagger
https://github.com/denganjia/openapi-schema
oas openapi rust swagger
Last synced: about 1 month ago
JSON representation
Rust structure mapped to Swagger
- Host: GitHub
- URL: https://github.com/denganjia/openapi-schema
- Owner: denganjia
- License: mit
- Created: 2023-05-22T07:45:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-21T02:12:47.000Z (over 1 year ago)
- Last Synced: 2024-10-01T07:01:32.369Z (about 2 months ago)
- Topics: oas, openapi, rust, swagger
- Language: Rust
- Homepage:
- Size: 191 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenApi-Schema
Rust structure mapped to openapi
You can use this package will openapi document into rust structure
# Use
```bash
cargo add openapi-schema
```
```rust
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