-
Notifications
You must be signed in to change notification settings - Fork 303
Open
Description

use actix_web::{get, HttpResponse, Responder};
pub const SECRET_TEXT: &'static str = "secret endpoint";
#[derive(utoipa::ToSchema, utoipa::ToResponse, serde::Serialize, serde::Deserialize)]
#[response(
description = "Override description for response",
content_type = "application/text"
)]
#[response(
example = json!(SECRET_TEXT)
)]
struct SecretText(&'static str);
impl Default for SecretText {
fn default() -> Self {
Self { 0: SECRET_TEXT }
}
}
impl SecretText {
const fn const_default() -> Self {
Self { 0: SECRET_TEXT }
}
}
const DEFAULT_SECRET_TEXT: SecretText = SecretText::const_default();
/// Shows secret to authenticated user (uses provided Bearer token from Header)
#[utoipa::path(
responses(
(status = 200, description = "secret endpoint", body=SecretText, example=SecretText::const_default)
),
security(("password"=[]))
)]
#[get("/secret")]
pub async fn secret() -> impl Responder {
HttpResponse::Ok().body(SECRET_TEXT)
}
…and yes I know example = json!
means it'll be JSON but it gave an error when I didn't use json!
.
Metadata
Metadata
Assignees
Labels
No labels