use std::borrow::Cow;
use crate::model::{Config, IgnoreItem};
use crate::rules::Level;
#[allow(dead_code)]
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
pub enum RuleConfigSchema {
Level(Level),
Table(RuleTableSchema),
}
#[allow(dead_code)]
#[derive(schemars::JsonSchema)]
#[serde(rename_all = "kebab-case")]
pub struct RuleTableSchema {
pub level: Option<Level>,
pub severity: Option<Level>,
#[serde(flatten)]
pub options: std::collections::BTreeMap<String, serde_json::Value>,
}
#[allow(dead_code)]
#[derive(schemars::JsonSchema)]
#[serde(untagged)]
enum IgnoreItemSchema {
Name(String),
Table(IgnoreItemTableSchema),
}
#[allow(dead_code)]
#[derive(schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
struct IgnoreItemTableSchema {
name: String,
reason: Option<String>,
}
impl schemars::JsonSchema for IgnoreItem {
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("IgnoreItem")
}
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
<IgnoreItemSchema as schemars::JsonSchema>::json_schema(generator)
}
}
#[must_use]
pub fn json_schema() -> serde_json::Value {
schemars::schema_for!(Config).to_value()
}