utoipa::openapi::response

Trait ResponseExt

Source
pub trait ResponseExt {
    // Required method
    fn json_schema_ref(self, ref_name: &str) -> Self;
}
Available on crate feature openapi_extensions only.
Expand description

Trait with convenience functions for documenting response bodies.

With a single method call we can add Content to our ResponseBuilder and Response that references a schema using content-type "application/json".

Add json response from schema ref.

use utoipa::openapi::response::{ResponseBuilder, ResponseExt};

let request = ResponseBuilder::new()
    .description("A sample response")
    .json_schema_ref("MyResponsePayload").build();

If serialized to JSON, the above will result in a response schema like this.

{
  "description": "A sample response",
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/MyResponsePayload"
      }
    }
  }
}

Required Methods§

Source

fn json_schema_ref(self, ref_name: &str) -> Self

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§