2017-02-16 1 views
0

응용 프로그램이 다른 메시지를 보내야하는 각 메시지의 서식을 지정하려면 Json 스키마를 만들어야합니다.속성 값에 따라 값 필요

나는 이미 구축 : 지금은

{ 
    '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' 
} 

, 내가 좋아하는, 명령 값에 따라 일부 속성이 필요 할 : 명령이 "읽기"로 잘 살고 경우

  • 를, 나는 명령이, 내가
,691,363 경로, 가치와 우선 순위를 필요로 할 "쓰기"로 잘 살고 경우
  • , 경로를 필요로 할210

    등 ...

    과 같은 몇 가지 주제를 보았지만 내 경우에는 초안 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' 
    }