diff --git a/utoipa-scalar/res/scalar.html b/utoipa-scalar/res/scalar.html index e35945b4..86c5a98f 100644 --- a/utoipa-scalar/res/scalar.html +++ b/utoipa-scalar/res/scalar.html @@ -1,7 +1,7 @@ - Scalar + $title Servable for Scalar { html: Cow::Borrowed(DEFAULT_HTML), url: url.into(), openapi, + title: Cow::Borrowed("Scalar"), } } } @@ -205,6 +207,7 @@ pub struct Scalar { url: Cow<'static, str>, html: Cow<'static, str>, openapi: S, + title: Cow<'static, str>, } impl Scalar { @@ -223,6 +226,7 @@ impl Scalar { html: Cow::Borrowed(DEFAULT_HTML), url: Cow::Borrowed("/"), openapi, + title: Cow::Borrowed("Scalar"), } } @@ -235,7 +239,7 @@ impl Scalar { /// At this point in time, it is not possible to customize the HTML template used by the /// [`Scalar`] instance. pub fn to_html(&self) -> String { - self.html.replace( + self.html.replace("$title", &self.title).replace( "$spec", &serde_json::to_string(&self.openapi).expect( "Invalid OpenAPI spec, expected OpenApi, String, &str or serde_json::Value", @@ -253,6 +257,22 @@ impl Scalar { self } + + /// Set a custom title for the HTML page. + /// + /// # Examples + /// + /// _**Set custom title for [`Scalar`].**_ + /// ``` + /// # use utoipa_scalar::Scalar; + /// # use serde_json::json; + /// Scalar::new(json!({"openapi": "3.1.0"})).title("My API"); + /// ``` + pub fn title>>(mut self, title: T) -> Self { + self.title = title.into(); + + self + } } /// Trait defines OpenAPI spec resource types supported by [`Scalar`].