本文整理匯總了Golang中github.com/go-openapi/spec.Schema.AdditionalProperties方法的典型用法代碼示例。如果您正苦於以下問題:Golang Schema.AdditionalProperties方法的具體用法?Golang Schema.AdditionalProperties怎麽用?Golang Schema.AdditionalProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-openapi/spec.Schema
的用法示例。
在下文中一共展示了Schema.AdditionalProperties方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestTypeResolver_AdditionalProperties
func TestTypeResolver_AdditionalProperties(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
if assert.NoError(t, err) {
// primitives as additional properties
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
parent := new(spec.Schema)
parent.AdditionalProperties = new(spec.SchemaOrBool)
parent.AdditionalProperties.Schema = sch
rt, err := resolver.ResolveSchema(parent, true, false)
if assert.NoError(t, err) {
assert.True(t, rt.IsMap)
assert.False(t, rt.IsComplexObject)
assert.Equal(t, "map[string]"+val.Expected, rt.GoType)
assert.Equal(t, "object", rt.SwaggerType)
}
}
// array of primitives as additional properties
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
parent := new(spec.Schema)
parent.AdditionalProperties = new(spec.SchemaOrBool)
parent.AdditionalProperties.Schema = new(spec.Schema).CollectionOf(*sch)
rt, err := resolver.ResolveSchema(parent, true, false)
if assert.NoError(t, err) {
assert.True(t, rt.IsMap)
assert.False(t, rt.IsComplexObject)
assert.Equal(t, "map[string][]"+val.Expected, rt.GoType)
assert.Equal(t, "object", rt.SwaggerType)
}
}
// refs as additional properties
for _, val := range schRefVals {
sch := new(spec.Schema)
sch.Ref, _ = spec.NewRef("#/definitions/" + val.Type)
parent := new(spec.Schema)
parent.AdditionalProperties = new(spec.SchemaOrBool)
parent.AdditionalProperties.Schema = sch
rt, err := resolver.ResolveSchema(parent, true, true)
if assert.NoError(t, err) {
assert.True(t, rt.IsMap)
assert.False(t, rt.IsComplexObject)
assert.Equal(t, "map[string]"+val.Expected, rt.GoType)
assert.Equal(t, "object", rt.SwaggerType)
}
}
// when additional properties and properties present, it's a complex object
// primitives as additional properties
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
parent := new(spec.Schema)
parent.Properties = make(map[string]spec.Schema)
parent.Properties["id"] = *spec.Int32Property()
parent.AdditionalProperties = new(spec.SchemaOrBool)
parent.AdditionalProperties.Schema = sch
rt, err := resolver.ResolveSchema(parent, true, true)
if assert.NoError(t, err) {
assert.True(t, rt.IsComplexObject)
assert.False(t, rt.IsMap)
assert.Equal(t, "map[string]"+val.Expected, rt.GoType)
assert.Equal(t, "object", rt.SwaggerType)
}
}
// array of primitives as additional properties
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
parent := new(spec.Schema)
parent.Properties = make(map[string]spec.Schema)
parent.Properties["id"] = *spec.Int32Property()
parent.AdditionalProperties = new(spec.SchemaOrBool)
parent.AdditionalProperties.Schema = new(spec.Schema).CollectionOf(*sch)
rt, err := resolver.ResolveSchema(parent, true, true)
if assert.NoError(t, err) {
assert.True(t, rt.IsComplexObject)
assert.False(t, rt.IsMap)
assert.Equal(t, "map[string][]"+val.Expected, rt.GoType)
assert.Equal(t, "object", rt.SwaggerType)
}
}
// refs as additional properties
//.........這裏部分代碼省略.........