JSON 模式:在错误消息中指定所需的最小/最大长度

问题描述 投票:0回答:0

我正在为 python 使用 jsonschema python 包。 我有以下架构:

{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "name": { "type": "string", "minLength": 5 } }, "additionalProperties": false }

此外,我还有以下JSON文件需要验证:

{ name: "Josh" }

当我根据上面的模式验证我的 JSON 文件时,我收到错误:

'Josh' is too short

有没有办法指定预期的最小长度? 像这样的东西:

The string 'Josh' is less than the minimum length of 5

我试过:

  • 更新 jsonschema 包到最新版本 - 4.17.3.
  • 使用 draft-07 而不是 draft-04.

这些操作都没有改变原始错误消息。

谢谢

jsonschema json-schema-validator
© www.soinside.com 2019 - 2024. All rights reserved.