简体   繁体   中英

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?

Guessing som sort of allOf but not quite sure how to use it.

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 . (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' }                        
            },
        }";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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