json - JSON Schema 验证非空正文
问题描述
我正在使用 JSON Schema 验证 API Gateway 请求,我还没有意识到它允许空请求,所以我想知道是否有一种方法可以通过模式验证我实际收到的东西。
这是我拥有的架构示例:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PutPetRequest",
"description": "Accepts a request to create or update a Pet.",
"type": "object",
"required": ["pet"],
"additionalProperties": false,
"properties": {
"pet": {
"description": "Pet object type",
"type": "object",
"required": [
"id"
],
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"format": "uuid"
}
}
}
}
}
一个空对象{}
将无法通过验证,但是
(空的,什么都没有)通过,我已经尝试过minProperties
,minItems
但我看到了相同的行为,这不可能吗?
解决方案
我遇到了类似的情况,将 minLength 设置为 1 至少需要 1 个字符。我知道这不是一个完美的解决方案,但这可以用作解决方法。
scope: {
title: 'my property',
description: 'description about my property',
type: JsonSchemaType.STRING,
minLength: 1,
},
推荐阅读
- react-native - React Native expo init 命令失败
- hyperledger-fabric - 另一个对等点会负责锚点对等点的功能吗
- java - 获取查询字符串值 JAVA
- ios - StackView 高度 Swift
- cloud-foundry - 在 Cloudfoundry 中,应用程序的 URL 是
- python - 逐行读取文件,如果行以数字开头,则在该行中添加所有这些数字
- oracle - Oracle 报告中的可选文本
- visual-studio-code - 打开最近工作区的 VS Code 热键是什么?
- alexa - 文档中的 Alexa Smart Home 错误响应不够清晰
- css - React 的样式化组件 vs jss vs 情感