可选类型的 JSONSchema 验证

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

到目前为止,我在我的 jsonschema 中使用它

"ApplicationContent": {
    "type": "string",
    "pattern": ".+"
},

我的 NodeJS 代码有

applicationContent: string | Record<string, unknown>;

如何编写 jsonschema 验证来验证 applicationContent 变量。

node.js json-schema-validator
1个回答
0
投票

下面的模式验证“字符串”和“记录

"ApplicationContent": {
    "type": ["string", "object"],
    "additionalProperties": { "type": "string" },
    "pattern": ".+"
  },
© www.soinside.com 2019 - 2024. All rights reserved.