错误响应 Schema
中级 JSON Schema
用于验证 API 错误响应的 JSON Schema,包含结构化错误详情。 一个真实、可直接使用的示例,你可以复制、调整,或用来测试自己的代码。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ErrorResponse",
"type": "object",
"properties": {
"status": { "const": "error" },
"error": {
"type": "object",
"properties": {
"code": { "type": "string" },
"message": { "type": "string" },
"details": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field": { "type": "string" },
"message": { "type": "string" }
}
}
}
},
"required": ["code", "message"]
},
"requestId": { "type": "string" }
},
"required": ["status", "error"]
} 更多示例
- schema
- error
- api