跳到內容

驗證規格

本文件說明由 api-specs-enriched 專案發佈的驗證規格之結構與內容。

驗證規格將 API 驗證限制條件、預設值及設定元資料整合至單一 JSON 檔案中。此規格由豐富化後的 OpenAPI 規格生成,並與其一同發佈。

發佈位置docs/specifications/api/validation.json

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"version": "2.1.0",
"generated_at": "2026-01-17T12:00:00Z",
"source": "api-specs-enriched",
"required_fields": { ... },
"enum_values": { ... },
"constraints": { ... },
"patterns": [ ... ],
"conditional_requirements": { ... },
"minimum_configurations": { ... },
"defaults": { ... },
"extensions": { ... }
}

指定每個資源各操作類型所需的欄位。

{
"required_fields": {
"common": {
"all_operations": ["metadata.name", "metadata.namespace"]
},
"resources": {
"origin_pool": {
"create": ["metadata.name", "metadata.namespace", "spec.origin_servers", "spec.port"],
"update": ["metadata.name", "metadata.namespace"],
"minimum_config": ["metadata.name", "metadata.namespace", "spec.origin_servers", "spec.port"]
}
}
}
}

定義受限制欄位的允許值。

{
"enum_values": {
"loadbalancer_algorithm": {
"description": "Load balancing algorithm for distributing traffic across origin servers",
"values": [
{"value": "ROUND_ROBIN", "description": "Each healthy endpoint selected in round robin order"},
{"value": "LEAST_REQUEST", "description": "Endpoint with fewest active requests selected"},
{"value": "RING_HASH", "description": "Consistent hashing using ring hash of endpoint names"},
{"value": "RANDOM", "description": "Random healthy endpoint selection"},
{"value": "LB_OVERRIDE", "description": "Hash policy inherited from parent load balancer"}
],
"default": "ROUND_ROBIN"
}
}
}

類型層級的驗證預設值及基於模式的規則。

{
"constraints": {
"type_defaults": {
"string": {"minLength": 0, "maxLength": 1024},
"integer": {"minimum": 0, "maximum": 2147483647}
}
}
}

基於欄位名稱模式的驗證規則,並附有信心分數。

{
"patterns": [
{
"pattern": "\\bport$",
"constraints": {"minimum": 1, "maximum": 65535},
"confidence": 0.99,
"description": "Valid TCP/UDP port range"
},
{
"pattern": "\\bname$",
"constraints": {
"minLength": 1,
"maxLength": 63,
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
},
"confidence": 0.90,
"description": "Kubernetes-style naming convention"
}
]
}

所有預設值依資源類型整理於統一結構中。

{
"defaults": {
"description": "All default values organized by resource type",
"resources": {
"healthcheck": {
"server_applied": {
"jitter": 0,
"jitter_percent": 0
},
"recommended": {
"timeout": 3,
"interval": 15,
"unhealthy_threshold": 1,
"healthy_threshold": 3,
"jitter_percent": 30
},
"oneof_recommended": {
"health_check": "http_health_check"
},
"nested_recommended": {
"http_health_check": {
"path": "/",
"use_http2": false,
"expected_status_codes": ["200"],
"use_origin_server_name": {}
}
}
},
"origin_pool": {
"server_applied": {
"no_tls": {},
"healthcheck": [],
"loadbalancer_algorithm": "ROUND_ROBIN",
"endpoint_selection": "DISTRIBUTED"
},
"recommended": {
"port": 443,
"connection_timeout": 2000,
"http_idle_timeout": 300000
},
"advanced_options": {
"connection_timeout": 2000,
"http_idle_timeout": 300000,
"same_as_endpoint_port": {},
"default_circuit_breaker": {},
"disable_outlier_detection": {}
},
"oneof_choices": {
"port_choice": "port",
"tls_choice": "no_tls",
"circuit_breaker_choice": "default_circuit_breaker"
},
"ui_vs_server": {
"loadbalancer_algorithm": {
"ui_default": "LB_OVERRIDE",
"server_default": "ROUND_ROBIN",
"note": "UI preselects LB_OVERRIDE but server applies ROUND_ROBIN if omitted"
}
}
},
"app_firewall": {
"server_applied": {
"allow_all_response_codes": {},
"default_anonymization": {},
"monitoring": {}
}
}
}
}
}
類別說明來源
server_applied欄位省略時 API 套用的值即時 API 測試
recommendedF5 XC 網頁主控台預先填入的值UI 分析
advanced_optionsadvanced_options 物件內的巢狀預設值API 探索
oneof_choices預設 OneOf 變體選擇API 行為
oneof_recommended建議的 OneOf 變體主控台預設值
nested_recommended巢狀結構描述的建議值UI 分析
ui_vs_serverUI 預設值與 API 預設值不同的情況比較分析

互斥欄位及條件式相依性。

{
"conditional_requirements": {
"resources": {
"healthcheck": {
"mutually_exclusive": [
{
"fields": ["spec.http_health_check", "spec.tcp_health_check", "spec.udp_icmp_health_check"],
"reason": "Choose exactly one health check type"
}
],
"conditional": []
}
}
}
}

最小可行設定及可運作範例。

{
"minimum_configurations": {
"resources": {
"origin_pool": {
"description": "Backend origin servers for load balancing",
"example": {
"metadata": {"name": "backend-pool", "namespace": "default"},
"spec": {
"origin_servers": [{"public_name": {"dns_name": "backend1.example.com"}}],
"port": 8080
}
}
}
}
}
}

豐富化後的 OpenAPI 規格使用以下擴充功能嵌入驗證元資料:

擴充功能用途位置
x-f5xc-required-for特定情境的必要欄位結構描述屬性
x-f5xc-server-default標記伺服器套用的預設值結構描述屬性
x-f5xc-recommended-value建議的預設值結構描述屬性
x-f5xc-recommended-oneof-variant建議的 OneOf 變體結構描述定義
x-f5xc-conditions條件式需求結構描述屬性
x-f5xc-minimum-configuration最小設定範例結構描述定義
x-f5xc-validation探索衍生的限制條件結構描述屬性
來源URL
GitHub Pageshttps://f5-sales-demo.github.io/api-specs-enriched/specifications/api/validation.json
Raw GitHubhttps://raw.githubusercontent.com/f5-sales-demo/api-specs-enriched/main/docs/specifications/api/validation.json

執行管線後:docs/specifications/api/validation.json

驗證規格於 version 欄位中遵循語意化版本規範:

變更類型版本遞增範例
重大結構變更主版本號欄位重新命名、章節移除
新增驗證規則或資源次版本號新增資源預設值
錯誤修正或說明更新修訂號錯字更正

當多個來源提供限制條件時,調和優先順序為:

  1. 現有 - 原始 OpenAPI 規格中的限制條件(最高優先順序)
  2. 探索 - 來自即時 API 探索的限制條件
  3. 推斷 - 來自模式比對的限制條件(最低優先順序)
版本日期變更內容
2.1.22026-01-18改寫為純 API 參考;新增 oneof_recommended 及 nested_recommended 類別
2.1.02026-01-18統一預設值結構,取代原有分散的各節
2.0.02026-01-15初始驗證規格