OpenAPI
Modified from utoipa, It uses simple proc macros which you can use to annotate your code to have items documented.
Crate Features
- yaml Enables serde_yaml serialization of OpenAPI objects.
- chrono Add support for chrono
DateTime
,Date
,NaiveDate
andDuration
types. By default these types are parsed tostring
types with additionalformat
information.format: date-time
forDateTime
andformat: date
forDate
andNaiveDate
according RFC3339 asISO-8601
. To override defaultstring
representation users have to usevalue_type
attribute to override the type. See docs for more details. - time Add support for time
OffsetDateTime
,PrimitiveDateTime
,Date
, andDuration
types. By default these types are parsed asstring
.OffsetDateTime
andPrimitiveDateTime
will usedate-time
format.Date
will usedate
format andDuration
will not have any format. To override defaultstring
representation users have to usevalue_type
attribute to override the type. See docs for more details. - decimal Add support for rust_decimal
Decimal
type. By default it is interpreted asString
. If you wish to change the format you need to override the type. See thevalue_type
in [ToSchema
derive docs][as_schema_derive]. - uuid Add support for uuid.
Uuid
type will be presented asString
with formatuuid
in OpenAPI spec. - smallvec Add support for smallvec.
SmallVec
will be treated asVec
. - indexmap Add support for indexmap. When enabled
IndexMap
will be rendered as a map similar toBTreeMap
andHashMap
.
Endpoint
Endpoint attribute macro implements OpenAPI path for the decorated function.
Macro accepts set of attributes that can be used to configure and override default values what are resolved automatically.
You can use the Rust's own #[deprecated]
attribute on functions to mark it as deprecated and it will reflect to the generated OpenAPI spec. Only parameters has a special deprecated attribute to define them as deprecated.
#[deprecated]
attribute supports adding additional details such as a reason and or since version but this is is not supported in OpenAPI. OpenAPI has only a boolean flag to determine deprecation. While it is totally okay to declare deprecated with reason #[deprecated = "There is better way to do this"]
the reason would not render in OpenAPI spec.
Doc comment at decorated function will be used for description
and summary
of the path. First line of the doc comment will be used as the summary
and the whole doc comment will be used as description
.
/// This is a summary of the operation
///
/// All lines of the doc comment will be included to operation description.
#[salvo_oapi::endpoint()]
fn endpoint() {}