-
Hi. What is the recommended way to do enveloping in OpenApi? The envelope is a made-up word, made by Flask-Restful, It is a way to wrap a response with a keyword such as // from
{
"build": "unknown",
"version": "0.1.0"
}
// to
{
"data": {
"build": "unknown",
"version": "0.1.0"
}
} My current approach is: -
+use crate::meta::model::DataWrapper;
pub struct MetaHandler;
#[OpenApi]
@@ -15,7 +15,10 @@ impl MetaHandler {
pub async fn find_meta(&self, ctx: Data<&Arc<ServerContext>>) -> FindMetaResponse {
let meta = ctx.meta_service.find_meta().await;
match meta {
- Ok(meta) => FindMetaResponse::Ok(Json(meta.into())),
+ Ok(meta) => {
+ let res = DataWrapper { data: meta.into() };
+ FindMetaResponse::Ok(Json(res))
+ },
Err(_) => FindMetaResponse::Internal,
}
} #[derive(Debug, Clone, Serialize, Deserialize, Object)]
+pub struct DataWrapper {
+ pub data: Meta,
+}
#[derive(ApiResponse)]
pub enum FindMetaResponse {
/// Return the specified user.
#[oai(status = 200)]
- Ok(Json<Meta>),
+ Ok(Json<DataWrapper>),
#[oai(status = 500)]
Internal,
} It works, but it will make redundant Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
sunli829
Mar 8, 2022
Replies: 2 comments 1 reply
-
Anyone has any input? |
Beta Was this translation helpful? Give feedback.
0 replies
-
This |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
azzamsa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This
DataWrapper
is necessary. 🙂