Module aide::transform

source ·
Expand description

Transformers wrap a part of or the entirety of OpenApi and enable modifications with method chaining in a declarative way.

§Examples

Example documentation for an imaginary government-provided API:

op.description("An example operation.")
    .response_with::<200, Json<String>, _>(|res| {
        res.description(
            "Something was probably successful, we don't know \
                    what this returns, but it's at least JSON.",
        )
    })
    .response_with::<500, Html<String>, _>(|res| {
        res.description("Sometimes arbitrary 500 is returned with randomized HTML.")
    })
    .default_response::<String>()

§Transform Functions

Transform functions are functions that accept a single transformer as a parameter and return it. They enable composability of documentation.

§Example

/// This transform function simply adds a no-content response as an example.
fn no_content(op: TransformOperation) -> TransformOperation {
    op.response::<204, ()>()
}

The above then can be (re)used using with.

    op.description("this operation always returns nothing")
        .with(no_content)

Structs§