简体   繁体   English

包含两个对象和一个布尔值的字符串的 JsonSchema 验证?

[英]JsonSchema validation of string containing two objects and one bool?

I'm looking to to reuse code from a project that looks like the first code block but need some help to do a json schema (second code block) that instead contains two objects and one bool and not just one object?我希望重用一个看起来像第一个代码块但需要一些帮助来执行 json 架构(第二个代码块)的代码,该架构包含两个对象和一个布尔值,而不仅仅是一个 object?

Guessing som sort of allOf but not quite sure how to use it.猜测 allOf 但不太确定如何使用它。

string schemaJson = @"{
            'description': 'onlyOneObject',
            'type': 'object',
            'properties': {
                'personId': { 'type': 'string', 'minLength' : 6 },
                'code': { 'type': 'string', 'minLength' : 3 }                       
             },
             'required' : [ 'personId' , 'code' ]
         }";
        
        JSchema schema = JSchema.Parse(schemaJson);

       

so something like this is what I need your expert help with as I'm not quite sure about the syntax.所以像这样的事情我需要你的专家帮助,因为我不太确定语法。

 string schemaJson = @"{
            'description': 'firstObject',
            'type': 'object',
            'properties': {
                'personId': { 'type': 'string', 'minLength' : 6 },
                'code': { 'type': 'string', 'minLength' : 3 }                       
             },
             'required' : [ 'personId' , 'code' ]

            'description': 'secondObject',  ??? Can I write the second object like this???
            'type': 'object',
            'properties': {
                'name': { 'type': 'string', 'minLength' : 6 },
                'code2': { 'type': 'string', 'minLength' : 3 }                       
             },
             'required' : [ 'name' , 'code2' ]

             'description': 'yeahOrNay',
             'type': 'bool'
             something something for bool???
         }";

So here was the answer I was looking for............ structure of a schemaJson containing two objects and a bool .所以这就是我正在寻找的答案......包含两个对象和一个 bool 的 schemaJson 结构 (not every single prop to validate as it was the structure I was after) (不是每一个道具都需要验证,因为它是我所追求的结构)

Cudos to myself as some deemed it impossible to answer based on the given information:)感谢我自己,因为有些人认为根据给定的信息无法回答:)

 string schemaJson = @"{
           'description': 'myObject',
           'type': 'object',
           'properties': {
           'firstObject': {
                'type': 'object',
                'properties': {
                'NUMBER': { 'type': 'integer' } 
                }
            },
           'secondObject': { 
                'type': 'object',
                'properties': {
                'NUMBER': { 'type': 'integer' } 
                }
            },
           'yeahOrNay': { 'type': 'boolean' }                        
            },
        }";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM