Trait utoipa::ToSchema

source ·
pub trait ToSchema<'__s> {
    // Required method
    fn schema() -> (&'__s str, RefOr<Schema>);

    // Provided method
    fn aliases() -> Vec<(&'__s str, Schema)> { ... }
}
Expand description

Trait for implementing OpenAPI Schema object.

Generated schemas can be referenced or reused in path operations.

This trait is derivable and can be used with [#derive] attribute. For a details of #[derive(ToSchema)] refer to derive documentation.

§Examples

Use #[derive] to implement ToSchema trait.

#[derive(ToSchema)]
#[schema(example = json!({"name": "bob the cat", "id": 1}))]
struct Pet {
    id: u64,
    name: String,
    age: Option<i32>,
}

Following manual implementation is equal to above derive one.

impl<'__s> utoipa::ToSchema<'__s> for Pet {
    fn schema() -> (&'__s str, utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>) {
         (
            "Pet",
            utoipa::openapi::ObjectBuilder::new()
                .property(
                    "id",
                    utoipa::openapi::ObjectBuilder::new()
                        .schema_type(utoipa::openapi::SchemaType::Integer)
                        .format(Some(utoipa::openapi::SchemaFormat::KnownFormat(
                            utoipa::openapi::KnownFormat::Int64,
                        ))),
                )
                .required("id")
                .property(
                    "name",
                    utoipa::openapi::ObjectBuilder::new()
                        .schema_type(utoipa::openapi::SchemaType::String),
                )
                .required("name")
                .property(
                    "age",
                    utoipa::openapi::ObjectBuilder::new()
                        .schema_type(utoipa::openapi::SchemaType::Integer)
                        .format(Some(utoipa::openapi::SchemaFormat::KnownFormat(
                            utoipa::openapi::KnownFormat::Int32,
                        ))),
                )
                .example(Some(serde_json::json!({
                  "name":"bob the cat","id":1
                })))
                .into(),
        ) }
}

Required Methods§

source

fn schema() -> (&'__s str, RefOr<Schema>)

Return a tuple of name and schema or reference to a schema that can be referenced by the name or inlined directly to responses, request bodies or parameters.

Provided Methods§

source

fn aliases() -> Vec<(&'__s str, Schema)>

Optional set of alias schemas for the ToSchema::schema.

Typically there is no need to manually implement this method but it is instead implemented by derive ToSchema when #[aliases(...)] attribute is defined.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'__s> ToSchema<'__s> for TupleUnit

impl<'__s> ToSchema<'__s> for DrawingVariant

impl<'__s> ToSchema<'__s> for UpdateDrawingsDto

impl<'__s> ToSchema<'__s> for SuggestionType

impl<'__s> ToSchema<'__s> for UpdateLayerDto

impl<'__s> ToSchema<'__s> for UpdatePlantingDto

impl<'__s> ToSchema<'__s> for DeciduousOrEvergreen

impl<'__s> ToSchema<'__s> for DrawingShapeType

impl<'__s> ToSchema<'__s> for Experience

impl<'__s> ToSchema<'__s> for ExternalSource

impl<'__s> ToSchema<'__s> for Fertility

impl<'__s> ToSchema<'__s> for GrowthRate

impl<'__s> ToSchema<'__s> for HerbaceousOrWoody

impl<'__s> ToSchema<'__s> for LayerType

impl<'__s> ToSchema<'__s> for LifeCycle

impl<'__s> ToSchema<'__s> for LightRequirement

impl<'__s> ToSchema<'__s> for Membership

impl<'__s> ToSchema<'__s> for PrivacyOption

impl<'__s> ToSchema<'__s> for PropagationMethod

impl<'__s> ToSchema<'__s> for Quality

impl<'__s> ToSchema<'__s> for Quantity

impl<'__s> ToSchema<'__s> for RelationType

impl<'__s> ToSchema<'__s> for Salutation

impl<'__s> ToSchema<'__s> for Shade

impl<'__s> ToSchema<'__s> for SoilPh

impl<'__s> ToSchema<'__s> for SoilTexture

impl<'__s> ToSchema<'__s> for Track

impl<'__s> ToSchema<'__s> for WaterRequirement

impl<'__s> ToSchema<'__s> for DrawingDto

impl<'__s> ToSchema<'__s> for EllipseProperties

impl<'__s> ToSchema<'__s> for FreeLineProperties

impl<'__s> ToSchema<'__s> for ImageProperties

impl<'__s> ToSchema<'__s> for LabelTextProperties

impl<'__s> ToSchema<'__s> for PolygonProperties

impl<'__s> ToSchema<'__s> for RectangleProperties

impl<'__s> ToSchema<'__s> for UpdateAddDateDrawingDto

impl<'__s> ToSchema<'__s> for UpdateNotesDrawingDto

impl<'__s> ToSchema<'__s> for DeleteLayerDto

impl<'__s> ToSchema<'__s> for LayerDto

impl<'__s> ToSchema<'__s> for RestoreDrawingLayerDto

impl<'__s> ToSchema<'__s> for DeletePlantingDto

impl<'__s> ToSchema<'__s> for MovePlantingDto

impl<'__s> ToSchema<'__s> for PlantingDto

impl<'__s> ToSchema<'__s> for TransformPlantingDto

impl<'__s> ToSchema<'__s> for UpdateAddDatePlantingDto

impl<'__s> ToSchema<'__s> for UpdatePlantingNoteDto

impl<'__s> ToSchema<'__s> for ArchiveSeedDto

impl<'__s> ToSchema<'__s> for BaseLayerImageDto

impl<'__s> ToSchema<'__s> for ConfigDto

impl<'__s> ToSchema<'__s> for Coordinates

impl<'__s> ToSchema<'__s> for DeleteBaseLayerImageDto

impl<'__s> ToSchema<'__s> for GainedBlossomsDto

impl<'__s> ToSchema<'__s> for GuidedToursDto

impl<'__s> ToSchema<'__s> for MapDto

impl<'__s> ToSchema<'__s> for NewMapDto

impl<'__s> ToSchema<'__s> for NewSeedDto

impl<'__s> ToSchema<'__s> for PlantsSummaryDto

impl<'__s> ToSchema<'__s> for RelationDto

impl<'__s> ToSchema<'__s> for RelationsDto

impl<'__s> ToSchema<'__s> for SeedDto

impl<'__s> ToSchema<'__s> for UpdateBaseLayerImageDto

impl<'__s> ToSchema<'__s> for UpdateGuidedToursDto

impl<'__s> ToSchema<'__s> for UpdateMapDto

impl<'__s> ToSchema<'__s> for UpdateMapGeometryDto

impl<'__s> ToSchema<'__s> for UsersDto

impl<'__s> ToSchema<'__s> for TimelineDto

impl<'__s> ToSchema<'__s> for TimelineEntryDto

impl<'__s, T> ToSchema<'__s> for ActionDtoWrapper<T>

impl<'__s, T> ToSchema<'__s> for TimelinePage<T>

impl<'__s, T> ToSchema<'__s> for Page<T>