1 回答

TA貢獻1890條經驗 獲得超9個贊
在 invopop/jsonschema 中使用 Go 標簽并不能很好地支持這些復雜的用例。任何打破常規用例的東西我都建議實施該JSONSchema()方法,以便您可以手動定義對象。按照你的例子:
type Boulou struct {
Name string `json:"name"`
Transformers []TransformerConfig `json:"transformers"`
}
func (Boulou) JSONSchema() *jsonschema.Schema {
props = orderedmap.New()
props.Set("name", &jsonschema.Schema{
Type: "string",
Title: "Name",
})
props.Set("transformers", &jsonschema.Schema{
Type: "array",
Title: "Transformers",
Items: &jsonschema.Schema{
Ref: ".....",
If: "properties.kind.const=convert_swim",
Then: "required[0]=convert_swim_config",
},
})
return &jsonschema.Schema{
Type: "object",
Title: "Boulou",
Properties: props,
}
}
我沒有直接測試過這個,但我相信你明白了。您需要手動弄清楚Ref您的TransformerConfig是什么。
更新:現在有一個新的PR #52,一旦發布,應該會更容易做到!
- 1 回答
- 0 關注
- 206 瀏覽
添加回答
舉報