Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions crates/aisix-admin/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,42 +2291,6 @@ fn add_missing_property_descriptions(doc: &mut Value) {
"/components/schemas/BedrockLatencyMode/oneOf/1/properties/kind",
"Latency mode that stops waiting after `timeout_ms`.",
),
(
"/components/schemas/Guardrail/oneOf/0/properties/kind",
"Guardrail provider type for literal and regular expression matching.",
),
(
"/components/schemas/Guardrail/oneOf/1/properties/kind",
"Guardrail provider type for Amazon Bedrock Guardrails.",
),
(
"/components/schemas/Guardrail/oneOf/2/properties/kind",
"Guardrail provider type for Azure Prompt Shield.",
),
(
"/components/schemas/Guardrail/oneOf/3/properties/kind",
"Guardrail provider type for Azure text moderation.",
),
(
"/components/schemas/Guardrail/oneOf/4/properties/kind",
"Guardrail provider type for Aliyun text moderation.",
),
(
"/components/schemas/Guardrail/oneOf/5/properties/kind",
"Guardrail provider type for in-process sensitive-data detection and redaction.",
),
(
"/components/schemas/Guardrail/oneOf/6/properties/kind",
"Guardrail provider type for Lakera Guard screening.",
),
(
"/components/schemas/Guardrail/oneOf/7/properties/kind",
"Guardrail provider type for the OpenAI Moderation API.",
),
(
"/components/schemas/Guardrail/oneOf/8/properties/kind",
"Guardrail provider type for PII detection and anonymization by a customer-run Presidio.",
),
(
"/components/schemas/KeywordPattern/oneOf/0/properties/kind",
"Pattern type for matching the value as plain text.",
Expand Down
34 changes: 34 additions & 0 deletions crates/aisix-core/src/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,9 @@ fn guardrail_kind_description(kind: &str) -> Option<&'static str> {
Some("Guardrail provider type for Azure text moderation.")
}
"aliyun_text_moderation" => Some("Guardrail provider type for Aliyun text moderation."),
"aliyun_ai_guardrail" => {
Some("Guardrail provider type for Aliyun AI Guardrails policy-driven moderation.")
}
"pii" => {
Some("Guardrail provider type for in-process sensitive-data detection and redaction.")
}
Expand Down Expand Up @@ -4656,4 +4659,35 @@ mod tests {
let err = validate_model(&v).unwrap_err();
assert!(err.message.contains("`retries`"), "{err:?}");
}

/// Every guardrail kind describes itself, and no two kinds share a
/// sentence. The generated Admin API reference has no other source for
/// these descriptions: a kind left undescribed here once inherited its
/// neighbour's text from a positional backfill list in the OpenAPI
/// assembly, documenting one provider as an unrelated one (#1037).
#[test]
fn every_guardrail_kind_carries_its_own_description() {
let schema = guardrail_root_schema();
let branches = schema["oneOf"]
.as_array()
.expect("the guardrail schema is a `oneOf` over the kinds");
let mut by_description: std::collections::BTreeMap<&str, &str> =
std::collections::BTreeMap::new();
for branch in branches {
let kind = branch["properties"]["kind"]["enum"][0]
.as_str()
.expect("each branch pins exactly one kind");
let description = branch["properties"]["kind"]["description"]
.as_str()
.unwrap_or_else(|| {
panic!(
"guardrail kind `{kind}` has no description; \
add an arm to `guardrail_kind_description`"
)
});
if let Some(other) = by_description.insert(description, kind) {
panic!("`{kind}` and `{other}` share one description: {description}");
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
1 change: 1 addition & 0 deletions schemas/resources/guardrail.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@
"description": "Where in the lifecycle this rule runs."
},
"kind": {
"description": "Guardrail provider type for Aliyun AI Guardrails policy-driven moderation.",
"enum": [
"aliyun_ai_guardrail"
],
Expand Down