pub trait Modify {
    fn modify(&self, openapi: &mut OpenApi);
}
Expand description

Trait that allows OpenApi modification at runtime.

Implement this trait if you wish to modify the OpenApi at runtime before it is being consumed (Before utoipa::OpenApi::openapi() function returns). This is trait can be used to add or change already generated OpenApi spec to alter the generated specification by user defined condition. For example you can add definitions that should be loaded from some configuration at runtime what may not be available during compile time.

See more about OpenApi derive at derive documentation.

Examples

Add custom JWT SecuritySchema to OpenApi.

#[derive(OpenApi)]
#[openapi(modifiers = [&SecurityAddon])]
struct ApiDoc;

struct SecurityAddon;

impl Modify for SecurityAddon {
   fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
       if let Some(components) = openapi.components.as_mut() {
           components.add_security_schema(
               "api_jwt_token",
               SecuritySchema::Http(
                   Http::new(HttpAuthenticationType::Bearer).with_bearer_format("JWT"),
               ),
           )
       }
   }
}

Required methods

Implementors