aws-api-gateway - AWS-API 网关——jsonschema 子对象应该在父对象存在时进行验证
问题描述
我需要为以下 JSON 输入创建 Jsonschema。仅当存在 Vehicle 对象时,才应需要 Vehicle 下的属性(例如制造商、模型等)。
{
"Manufacturer": "",
"Characteristics": {
"Starts": "new",
"vehicle": {
"Manufacturer": "hello",
"Model": "hh",
"Opening": "",
"Quantity": "",
"Principle": "",
"Type": ""
}
}
}
我尝试了以下 JsonSchema 但这在 Vehicle 对象不存在时有效但如果我们将 Vehicle 重命名为其他一些 ex: Vehicle1 它不会给出错误。请指导我如何解决这个问题。
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"Manufacturer": {
"type": [
"string",
"null"
]
},
"Characteristics": {
"type": "object",
"properties": {
"Starts": {
"type": [
"string",
"null"
]
},
"Vehicle": {
"$ref": "#/definitions/Vehicle"
}
},
"required": [
"Starts", "Vehcle"
]
}
},
"required": [
"Manufacturer"
],
"definitions": {
"Vehicle": {
"type": "object",
"properties": {
"Manufacturer": {
"type": [
"string",
"null"
]
},
"Model": {
"type": [
"string",
"null"
]
},
"Opening": {
"type": [
"string",
"null"
]
},
"PanelQuantity": {
"type": [
"string",
"null"
]
},
"Principle": {
"type": [
"string",
"null"
]
},
"Type": {
"type": [
"string",
"null"
]
}
},
"required": ["Manufacturer", "Model", "Opening", "Quantity", "Principle", "Type"]
}
}
}
谢谢,巴斯卡
解决方案
听起来您想添加"additionalProperties": false
- 如果存在任何其他未在properties
.
推荐阅读
- python - 基于带有循环的模式匹配两个列表的元素
- sql - 使用 VBA 将表从 sql server 导出到访问表
- javascript - jQuery 平滑滚动以在移动设备上使用固定菜单锚定
- elasticsearch - SQL Server 数据库 > Logstash > Elasticsearch:将与同一实体相关的结果集记录映射到同一 ES 文档
- android - 安卓 Facebook 登录。防止按钮更改为“注销”
- flutter - 如何使用 Flutter Web 将数据保存在浏览器的 cookie 中?
- java - 使用 Maven Shade 构建应用程序 jar 时,排除所有 META-INF/versions 目录/文件是否安全?
- amazon-dynamodb - 查询 DynamoDB 表以按创建日期获取前 100 条记录的顺序
- excel - 记住位于另一列的一列中的公式的前一个值
- python-3.x - 如何将生成的 AsyncResult 传递给 FastAPI python 中的其他 API