JSON格式的正则表达式

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

如何为快速创建属性并以api模式格式创建属性的json模式添加正则表达式验证,并且只能包含所有大写/小写字母,数字,斜杠(/)和花括号{}

例如:

/ someapi / v1 / {usename}

/ someApi / v1 / {userName}

这是我的Uschema:

     {
      "type": "object",
      "patternProperties": {
       "^[a-zA-Z0-9{}/]": {
         "additionalProperties": false,
         "type": "object",
         "patternProperties": {
           "^(EMP|MGR|ACCT)$": {
            "additionalProperties": false,
            "type": "object"
          }
        }
     }
   }
 }

这是JSON和使用ajv的结果(规范7)

我的JSON示例:

{"/employee/v1/{empId}":{"EMP":{}}} - PASS
{"/employee/v1/{empId}":{"E1MP":{}}} - FAIL (I can understand as E1MP is there)
{"/employee/v1/{empId}/<fooBar>":{"E1MP":{}}} - FAIL 
(I can understand as E1MP is there but didn't complain about < > 
brackets as it was the first entry to validate)

{"/employee/v1/{empId}/<fooBar>":{"EMP":{}}} - PASS (?)
(Actually it should FAIL ???, Why it is considering the < > brackets though I have the regex in place for the outer parent property.)

此外,如果我调整外部正则表达式以验证任何空空间,例如:^ [a-zA-Z0-9 {} / \ s],它不会抱怨这些空间有任何错误:

{"/emp loye  e/v1/{empI   d}/{f  ooBar}":{"EMP":{}}} -- PASS? (Actually it shoud FAIL ???)
json jsonschema json-schema-validator ajv
1个回答
1
投票

您的架构有两个问题。

© www.soinside.com 2019 - 2024. All rights reserved.