impl_poem_type

Macro impl_poem_type 

Source
macro_rules! impl_poem_type {
    ($ty:ty, $spec_type:literal, ($($key:ident = $value:expr),*)) => { ... };
}
Expand description

This macro allows you to use a type in a request / response type for use with poem-openapi. In order to use this macro, your type must implement Serialize and Deserialize, so we can encode it as JSON / a string.

With this macro, you can express what OpenAPI type you want your type to be expressed as in the spec. For example, if your type serializes just to a string, you likely want to invoke the macro like this:

impl_poem_type!(MyType, “string”, ());

If your type is more complex, and you’d rather it become an “object” in the spec, you should invoke the macro like this:

impl_poem_type!(MyType, “object”, ());

This macro supports applying additional information to the generated type. For example, you could invoke the macro like this:

impl_poem_type!( HexEncodedBytes, “string”, ( example = Some(serde_json::Value::String( “0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1”.to_string())), description = Some(“A hex encoded string”), ) );

To see what different metadata you can apply to the generated type in the spec, take a look at MetaSchema here: https://github.com/poem-web/poem/blob/master/poem-openapi/src/registry/mod.rs