2017-02-16 6 views
0

アプリケーションが別のものに送信する必要がある各メッセージをフォーマットするために、Jsonスキーマを構築する必要があります。プロパティ値に応じて値を要求する

私はすでにこの構築:私は、コマンドは「読み」するsettedされている場合

  • :今のところ

    { 
        'description': 'BLABLA', 
        'definitions': { 
         'M2M_message_input' : { 
          'type' : 'object', 
          'properties' : { 
           'command' : { 
            'type': 'string', 
            'enum' : ['read', 'write', 'list', 'reset priority'] 
           }, 
           'path' : { 
            'type' : 'string', 
            'pattern' : '^\/' 
           }, 
           'value' : {'type' : 'string'}, 
           'priority' : { 
            'type' : 'integer', 
            'maximum' : 255, 
            'exclusiveMaximum' : false, 
            'minimum' : 0, 
            'exclusiveMinimum' : false 
           } 
          }, 
          'required': ['command'], 
          'dependencies' : { 
           'value' : ['priority'] 
          }, 
          "additionalProperties" : false 
         } 
        }, 
        'type': 'object', 
        '$ref' : '#/definitions/M2M_message_input' 
    } 
    

    を、私のような指令値に応じて、いくつかのプロパティを、必要とする場合、コマンドが「書き込み」にsettedされている場合、私はパスを要求したい

  • 、パスを必要とする値と優先順位

など...

JSON Schema - specify field is required based on value of another fieldのようないくつかの話題がありましたが、私の場合はv4のドラフトでは対応できませんでした。

提案がありますか?

答えて

0

は道を見つけた:

{ 
    'description': '[...]', 
    'definitions': { 
     'readParameter' : { 
      'type' : 'object', 
      'required' : ['command','path'], 
      'properties' : { 
       'command' : { 
        'type' : 'string', 
        'enum' : ['read'] 
       }, 
       'path' : { 
        'type' : "string" 
       } 
      }, 
      "additionalProperties" : false 
     }, 
     'writeParameter' : { 
      'type' : 'object', 
      'required' : ['command','path', 'value', 'priority'], 
      'properties' : { 
       'command' : { 
        'type' : 'string', 
        'enum' : ['write'] 
       }, 
       'path' : { 
        'type' : "string" 
       }, 
       'value' : { 
        'type' : "string" 
       }, 
       'priority' : { 
        'type' : 'integer', 
        'maximum' : 255, 
        'exclusiveMaximum' : false, 
        'minimum' : 0, 
        'exclusiveMinimum' : false 
       } 
      }, 
      "additionalProperties" : false 
     }, 

     'listParameter' : { 
      'type' : 'object', 
      'required' : ['command'], 
      'properties' : { 
       'command' : { 
        'type' : 'string', 
        'enum' : ['list'] 
       } 
      }, 
      "additionalProperties" : false 
     }, 


     'M2M_message_input' : { 
      'type' : 'object', 
      'oneOf': [ 
        { "$ref": "#/definitions/readParameter" }, 
        { "$ref": "#/definitions/writeParameter" }, 
        { "$ref": "#/definitions/listParameter" } 
      ], 
     } 
    }, 
    'type': 'object', 
    '$ref' : '#/definitions/M2M_message_input' 
} 
関連する問題