跳转到内容

验证规范

本文档介绍由 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 Web 控制台预填充的值UI 分析
advanced_optionsadvanced_options 对象内的嵌套默认值API 发现
oneof_choices默认 OneOf 变体选择API 行为
oneof_recommended推荐的 OneOf 变体控制台默认值
nested_recommended嵌套 Schema 的推荐值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特定上下文的必填字段Schema 属性
x-f5xc-server-default标记服务端应用的默认值Schema 属性
x-f5xc-recommended-value推荐默认值Schema 属性
x-f5xc-recommended-oneof-variant推荐的 OneOf 变体Schema 定义
x-f5xc-conditions条件要求Schema 属性
x-f5xc-minimum-configuration最小配置示例Schema 定义
x-f5xc-validation通过发现推导的约束Schema 属性
来源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. 已有约束(Existing) — 原始 OpenAPI 规范中的约束(最高优先级)
  2. 发现约束(Discovery) — 来自实时 API 发现的约束
  3. 推断约束(Inferred) — 来自模式匹配的约束(最低优先级)
版本日期变更内容
2.1.22026-01-18重写为纯 API 参考文档;新增 oneof_recommended 和 nested_recommended 分类
2.1.02026-01-18统一 defaults 结构,替代原有分散章节
2.0.02026-01-15初始验证规范