use std::collections::BTreeMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct OpenApiConfig {
pub enabled: bool,
pub path: String,
pub servers: Vec<String>,
pub include_undocumented: bool,
pub output: Option<PathBuf>,
}
impl Default for OpenApiConfig {
fn default() -> Self {
Self {
enabled: false,
path: "/openapi.json".into(),
servers: Vec::new(),
include_undocumented: true,
output: None,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct SwaggerConfig {
pub enabled: bool,
pub path: String,
pub title: Option<String>,
pub spec_url: Option<String>,
pub allow_external_spec: bool,
pub deep_linking: bool,
pub doc_expansion: String,
pub filter: bool,
pub try_it_out: bool,
pub display_request_duration: bool,
pub persist_authorization: bool,
pub display_operation_id: bool,
pub default_models_expand_depth: i64,
pub options: BTreeMap<String, toml::Value>,
}
impl Default for SwaggerConfig {
fn default() -> Self {
Self {
enabled: false,
path: "/docs".into(),
title: None,
spec_url: None,
allow_external_spec: false,
deep_linking: true,
doc_expansion: "list".into(),
filter: false,
try_it_out: false,
display_request_duration: false,
persist_authorization: false,
display_operation_id: false,
default_models_expand_depth: 1,
options: BTreeMap::new(),
}
}
}
pub(crate) const SWAGGER_TYPED_OPTIONS: &[(&str, &str)] = &[
("deep_linking", "deepLinking"),
("doc_expansion", "docExpansion"),
("filter", "filter"),
("try_it_out", "tryItOutEnabled"),
("display_request_duration", "displayRequestDuration"),
("persist_authorization", "persistAuthorization"),
("display_operation_id", "displayOperationId"),
("default_models_expand_depth", "defaultModelsExpandDepth"),
];
pub(crate) const SWAGGER_RESERVED_OPTIONS: &[&str] = &["url", "dom_id", "domNode", "spec"];
pub(crate) const DOC_EXPANSIONS: &[&str] = &["list", "full", "none"];