定制的OpenAPI架构,配以生锈,火箭和Okapi
我正在使用Rocket作为主框架开发带有Rust的API。 为了创建Swagger Docs,我使用OKAPI,这使我可以自动创建文档。
use rocket_okapi::swagger_ui::*;
extern crate dotenv;
use rocket_okapi::{openapi, openapi_get_routes};
#[openapi] // Let okapi know that we want to document this endpoing
#[get("/test_route")]
fn test_route() -> &'static str {
"test_route"
}
#[rocket::main]
pub async fn main() -> () {
rocket::build()
// Mount routes with `openapi_get_routes` instead of rocket `routes``
.mount("/", openapi_get_routes![test_route])
// Mount swagger-ui on thisroute
.mount(
"/docs",
make_swagger_ui(&SwaggerUIConfig {
// The automatically generated openapi.json will be here
url: "../openapi.json".to_owned(),
..Default::default()
}),
)
.launch()
.await
.unwrap();
()
}
那挺好的。但是我想为API提供OKAPI的设置,但我无法做到这一点。我知道有一个示例
另外,我想加载自定义OpenApi.json
;但是我不知道该如何实现。
I am developing an API with Rust, using Rocket as main framework.
To create the Swagger docs I use Okapi, which allows me to create the docs automatically.
use rocket_okapi::swagger_ui::*;
extern crate dotenv;
use rocket_okapi::{openapi, openapi_get_routes};
#[openapi] // Let okapi know that we want to document this endpoing
#[get("/test_route")]
fn test_route() -> &'static str {
"test_route"
}
#[rocket::main]
pub async fn main() -> () {
rocket::build()
// Mount routes with `openapi_get_routes` instead of rocket `routes``
.mount("/", openapi_get_routes![test_route])
// Mount swagger-ui on thisroute
.mount(
"/docs",
make_swagger_ui(&SwaggerUIConfig {
// The automatically generated openapi.json will be here
url: "../openapi.json".to_owned(),
..Default::default()
}),
)
.launch()
.await
.unwrap();
()
}
Thats good. But I would like to provide okapi the settings for the API, and I wasnt able to do that. I know there is an example at https://github.com/GREsau/okapi/blob/master/examples/custom_schema/src/main.rs, but I couldnt load a custom OpenApi
schema in my api.
Also, I would like to load a custom openapi.json
; but I don't know how to achieve that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论