poem-openapi 5.1.16

OpenAPI support for Poem.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use poem::{Endpoint, endpoint::make_sync, web::Html};

const TEMPLATE: &str = include_str!("stoplight-elements.html");

pub(crate) fn create_html(document: &str) -> String {
    TEMPLATE.replace("'{:spec}'", document)
}

pub(crate) fn create_endpoint(document: String) -> impl Endpoint {
    let ui_html = create_html(&document);
    poem::Route::new().at("/", make_sync(move |_| Html(ui_html.clone())))
}