循環依存を引き起こさずに互いに参照する2つのフィールドを定義する方法を教えてください。JSONスキーマ定義における循環依存の回避
次の例では、min_percentageの最大値をmax_percentageの最小値に、max_percentageの最小値をmin_percentageの最大値にしたいとします。
だから
"min_percentage": {
"type": "integer",
"minimum" : 1,
"maximum" : 99
}
"max_percentage": {
"type": "integer",
"minimum" : 2,
"maximum" : 150
}
は
"min_percentage": {
"type": "integer",
"minimum" : 1,
"maximum" : "#max_percentage#minimum"
}
"max_percentage": {
"type": "integer",
"minimum" : "#min_percentage#maximum",
"maximum" : 150
}
EDITのようなものになり:私はPOSSIBLEソリューションはだろうと思った。..
これは、スキーマの依存関係を使用して可能性があり https://spacetelescope.github.io/understanding-json-schema/reference/object.html?highlight=default
max_perを指定するだけですmin_percentageを依存関係にすると、#min_percentage#maximumは、#max_percentage#minimumに基づいて、循環依存性を取り除くことができます。
"max_percentage": {
"type": "integer",
"minimum" : 2,
"maximum" : 150
}
"dependencies": {
"max_percentage": {
"properties": {
"min_percentage": {
"type": "integer",
"minimum" : 1,
"maximum" : "#max_percentage#minimum"
}
},
"required": ["min_percentage"]
}
}
しかし、どうやらこれは... Can JSON integer attributes be referenced?
感謝を行うことはできません。
しかし、これはmin_percentage#maximumとmax_percentage#minimumの両方をmin_max_percentageに制限しませんか?もしそうなら、私はそれらが変わることができるので、それをしたくありませんでした。 コードの場合、min_max_percentageを最初の項目セットの値にすることができます。つまり、max_percentage#minimumが最初に設定された場合、これは新しい値になり、min_percentage#maximumの設定に反映されます。トリックは、JSONの検証中にこれを行うスキーマを取得することです、任意のアイデア? – Dodomac
JSONはコードではなく、むしろ__efficient__オブジェクト__notation__のためのものです。完全に吹き飛ばされたリレーショナルモデルを表現しようとするなら、XMLのようなものを使う方が良いでしょう。特に、DOM(Document Object Model)とそれに関連するリファレンスを備えており、 'Schema validation'を行うこともできます。 – HeroicKatora