Is there a way to default all properties as required in json-schema?

时间:2015-07-31 19:35:19

标签: json jsonschema

I am making a fairly large json-schema (draft 4) and want all properties to be required, without having to add each property to the required array. Is it possible to set all properties as required by default?

1 个答案:

答案 0 :(得分:2)

json-schema中没有任何内容可以使默认情况下需要属性。

如果手动生成属性列表有问题,我建议如下。

  1. 定义一个新的关键字,添加您想要的功能。
  2. 使用新关键字编写模式。
  3. 编写一个带有扩展json-schema的函数,并返回一个标准的json-schema。
  4. 在您喜欢的json-schema验证器中使用生成的标准模式。
  5. 这种方法允许您以最方便的方式编写模式,同时仍然可以使用标准工具。如果您认为您的扩展可能对其他人有用,您也可以建议将其添加到json-schema规范的下一个草案中。

相关问题