juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.47k stars 192 forks source link

generate type: object #642

Closed incker closed 1 year ago

incker commented 1 year ago

Hello!

If i need to generate someting like

lg:
    type: object

My rust code:

#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
pub struct Layout {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lg: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub md: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sm: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub xs: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub xxs: Option<serde_json::Value>,
}

My swagger generated code:

"layout": {
    "lg": "string",
    "md": "string",
    "sm": "string",
    "xs": "string",
    "xxs": "string"
},

Thank you !

incker commented 1 year ago

One more note...

   --> dashd/miner-dash-daemon/src/gen_api_docs.rs:66:1
    |
66  | serde_json::Value,
    | ^^^^^^^^^^ the trait `ToSchema<'_>` is not implemented for `serde_json::Value`
    |
    = help: the following other types implement trait `ToSchema<'__s>`
JMLX42 commented 1 year ago

Answer here IMHO: https://github.com/juhaku/utoipa/issues/383#issuecomment-1335152273