Derive Macro poem_openapi::Object

source ·
#[derive(Object)]
{
    // Attributes available to this derive:
    #[oai]
}
Expand description

Define a OpenAPI object

§Macro parameters

AttributeDescriptionTypeOptional
renameRename the objectstringY
rename_allRename all the fields according to the given case convention. The possible values are “lowercase”, “UPPERCASE”, “PascalCase”, “camelCase”, “snake_case”, “SCREAMING_SNAKE_CASE”, “kebab-case”, “SCREAMING-KEBAB-CASE”.stringY
defaultDefault valuebool,stringY
deprecatedSchema deprecatedboolY
read_only_allSet all fields openapi readOnly propertyboolY
write_only_allSet all fields openapi writeOnly propertyboolY
deny_unknown_fieldsAlways error during parsing when encountering unknown fields.boolY
exampleIndicates that the object type has implemented Example traitboolY
external_docsSpecify a external resource for extended documentationstringY
remoteDerive a remote objectstringY
skip_serializing_if_is_noneSkip serializing field if the value is none.boolY
skip_serializing_if_is_emptySkip serializing field if the value is empty.boolY

§Field parameters

AttributeDescriptionTypeOptional
skipSkip this fieldboolY
renameRename the fieldstringY
defaultDefault valuebool,stringY
read_onlyset field openapi readOnly propertyboolY
write_onlyset field openapi writeOnly property boolboolY
flattenSimilar to serde (flatten)boolY
skip_serializing_if_is_noneSkip serializing this field if the value is none.boolY
skip_serializing_if_is_emptySkip serializing this field if the value is empty.boolY
skip_serializing_ifCall a function to determine whether to skip serializing this field.stringY
validator.multiple_ofThe value of “multiple_of” MUST be a number, strictly greater than 0. A numeric instance is only valid if division by this value results in an integer.numberY
validator.maximumThe value of “maximum” MUST be a number, representing an upper limit for a numeric instance. If exclusive is true and instance is less than the provided value, or else if the instance is less than or exactly equal to the provided value.{ value: <number>, exclusive: <bool>}Y
validator.minimumThe value of “minimum” MUST be a number, representing a lower limit for a numeric instance. If exclusive is true and instance is greater than the provided value, or else if the instance is greater than or exactly equal to the provided value.{ value: <number>, exclusive: <bool>}Y
validator.max_lengthThe value of “max_length” MUST be a non-negative integer. A string instance is valid against this validator if its length is less than, or equal to, the value.usizeY
validator.min_lengthThe value of “min_length” MUST be a non-negative integer. The value of this validator MUST be an integer. This integer MUST be greater than, or equal to, 0.usizeY
validator.patternThe value of “pattern” MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. A string instance is considered valid if the regular expression matches the instance successfully.stringY
validator.max_itemsThe value of “max_items” MUST be an integer. This integer MUST be greater than, or equal to, 0. An array instance is valid if its size is less than, or equal to, the value of this validator.usizeY
validator.min_itemsThe value of “min_items” MUST be an integer. This integer MUST be greater than, or equal to, 0. An array instance is valid if its size is greater than, or equal to, the value of this validator.usizeY
validator.unique_itemsThe value of “unique_items” MUST be an boolean. If this value is false, the instance validates successfully. If this value is true, the instance validates successfully if all of its elements are unique.boolY
validator.max_propertiesThe value of this keyword MUST be a non-negative integer. An object instance is valid against “maxProperties” if its number of properties is less than, or equal to, the value of this keyword.usizeY
validator.min_propertiesThe value of this keyword MUST be a non-negative integer. An object instance is valid against “minProperties” if its number of properties is greater than, or equal to, the value of this keyword.usizeY

§Examples

use poem_openapi::Object;

/// Pet
#[derive(Object)]
struct Pet {
    /// The id of this pet.
    id: String,

    /// The name of this pet.
    name: String,
}