salvo_oapi
allows you to easily implement Apis that comply with the OpenApiv3
specification.
It uses procedural macros to generate a lots of boilerplate code, so that you only need to focus on the more
important business implementations.
Features
- Type safety If your codes can be compiled, then it is fully compliant with the
OpenApi v3
specification. - Rustfmt friendly Do not create any DSL that does not conform to Rust's syntax specifications.
- IDE friendly Any code generated by the procedural macro will not be used directly.
- Minimal overhead All generated code is necessary, and there is almost no overhead.
Crate features
To avoid compiling unused dependencies, salvo_oapi gates certain features, some of which are disabled by default:
Feature | Description |
---|---|
chrono | Integrate with the chrono crate. |
swagger-ui | Add swagger UI support |
Support for email address string | |
hostname | Support for hostname string |
uuid | Integrate with the uuid crate |
url | Integrate with the url crate |
bson | Integrate with the bson crate |
rust_decimal | Integrate with the rust_decimal crate |
static-files | Support for static file response |
Safety
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% Safe Rust.
Example
use *;
use QueryParam;
async
async
This feature needs to be opted-in. It can be done by adding the feature in Cargo.toml
file
[]
= { = "0.39", = ["oapi"]}
= { = "1", = ["full"] }
Run example
Open http://localhost:5800/
in your browser, you will see the Swagger UI
that contains these Api definitions.
> cargo run --example hello_world
> curl http://localhost:5800
hello!
> curl http://localhost:5800\?name\=chris
hello, chris!
Contributing
:balloon: Thanks for your help improving the project! We are so happy to have you!
License
Licensed under either of
- Apache License, Version 2.0,(LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in salvo_oapi by you, shall be licensed as Apache, without any additional terms or conditions.