2017-12-14 31 views
1

私はJSONをgenereted:JSONスキーマ - 同じデータ型を持つオブジェクト

{ 
"someString" : "example", 
"obj1" : { 
    "opt1" : 1, 
    "opt2" : 1, 
    "opt3" : "aaa" 
}, 
"obj2" : { 
    "opt1" : 55, 
    "opt2" : 55, 
    "opt3" : "bbb" 
} 
} 

と同じデータ型(OPT1、OPT2で(OBJ1、OBJ2、OBJ3、OBJ4、...)のオブジェクトのよりがあるだろう、 opt3)

今、私はこのためのスキーマを作成したいのですが、スキーマ内のすべてのオブジェクトをどのように組み合わせるのか分かりません。

EDIT:

root: { 
    "type" : "object", 
    "oneOf" : [ 
     { 
     "properties" : { 
      "someString" : { "type" : "string" } 
     }, 
     "patternProperties" : { "^.*$" : { "$ref" : "./schemas/myPatternProperties.json#" } }, 
     "additionalProperties" : false } 
     } 
    ] 
} 

とmuPatternProperties.jsonが見えます::、私の生成JSONはまだこのスキーマとして認識されていないので、何か問題が

{ 
    "type" : "object", 
    "properties" : { 
     "opt1" : { "type" : "number" }, 
     "opt2" : { "type" : "number" }, 
     "opt3" : { "type" : "string" }, 
    } 
    "required" : [ "opt1", "opt2", "opt3" ] 
} 

あり、私はスキーマを作成し

タイプ。

答えて

1

あなたの問題はdescribe object with a lot of properties with the same type and some naming rulesです。あなたは建設がプロパティのpattern to matchを指定することをpatternPropertiesセクション

{ 
    "patternProperties": { 
     "^(/[^/]+)+$": { "$ref": "http://some.site.somewhere/entry-schema#" } 
} 

を指定しなければならないことを解決するには。例how to use patternProperties続きを読むspecification

UPDATE

で実際に完全なスキームは、もちろんその

{ 
    "$schema": "http://json-schema.org/draft-06/schema#", 
    "type": "object", 
    "properties": { 
     "someString": { 
      "type": "string" 
     } 
    }, 
    "patternProperties": { 
     "^obj([0-9]+)$": { 
      "$ref": "#/definitions/objEntity" 
     } 
    }, 
    "additionalProperties": false, 
    "required": [ "someString" ], 

    "definitions": { 
     "objEntity": { 
      "type": "object", 
      "properties": { 
       "opt1": { "type": "number" }, 
       "opt2": { "type": "number" }, 
       "opt3": { "type": "string" } 
      }, 
      "required": ["opt1", "opt2", "opt3"] 
     } 
    } 
} 

のようなものでなければならない、あなたは、1つの以上のファイルにそのスキームを分割し、入力したリンクを変更することができます定義。

+0

返信パターンありがとうございました。私はスキーマをいくつか作成しました。私はまだ正しく動作していないので、このスキーマで何かを逃したと思う。 –

+0

エラーメッセージが表示されますか?あなたのサンプルデータは実際にJSONBuddyで妥当性が確認されています。 – Clemens

+0

いいえ、私は取得しません。スキームをチェックするには、[JSON Schema Validator](https://www.jsonschemavalidator.net/) – RQman

関連する問題