pub trait RequestBodyExt {
    fn json_component_ref(self, ref_name: &str) -> Self;
}
Expand description

Trait with convenience functions for documenting request bodies.

This trait requires a feature-flag to enable:

[dependencies]
utoipa = { version = "1", features = ["openapi_extensions"] }

Once enabled, with a single method call we can add Content to our RequestBodyBuilder that references a crate::ToSchema schema using content-tpe “application/json”:

use utoipa::openapi::request_body::{RequestBodyBuilder, RequestBodyExt};

let request = RequestBodyBuilder::new().json_component_ref("EmailPayload").build();

If serialized to JSON, the above will result in a requestBody schema like this:

{
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/EmailPayload"
      }
    }
  }
}

Required Methods

Add Content to RequestBody referring to a schema with Content-Type application/json.

Implementors