本文整理汇总了Golang中github.com/vikstrous/go-swagger/spec.Schema.Extensions方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.Extensions方法的具体用法?Golang Schema.Extensions怎么用?Golang Schema.Extensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vikstrous/go-swagger/spec.Schema
的用法示例。
在下文中一共展示了Schema.Extensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTypeResolver_AnonymousStructs
func TestTypeResolver_AnonymousStructs(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
if assert.NoError(t, err) {
// anonymous structs should be accounted for
parent := new(spec.Schema)
parent.Typed("object", "")
parent.Properties = make(map[string]spec.Schema)
parent.Properties["name"] = *spec.StringProperty()
parent.Properties["age"] = *spec.Int32Property()
rt, err := resolver.ResolveSchema(parent, true)
if assert.NoError(t, err) {
assert.False(t, rt.IsNullable)
assert.True(t, rt.IsAnonymous)
assert.True(t, rt.IsComplexObject)
}
parent.Extensions = make(spec.Extensions)
parent.Extensions["x-isnullable"] = true
rt, err = resolver.ResolveSchema(parent, true)
if assert.NoError(t, err) {
assert.True(t, rt.IsNullable)
assert.True(t, rt.IsAnonymous)
assert.True(t, rt.IsComplexObject)
}
}
}
示例2: TestTypeResolver_BasicTypes
func TestTypeResolver_BasicTypes(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
if assert.NoError(t, err) {
// primitives and string formats
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
rt, err := resolver.ResolveSchema(sch, true)
if assert.NoError(t, err) {
assert.False(t, rt.IsNullable)
assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt)
}
}
// arrays of primitives and string formats
for _, val := range schTypeVals {
var sch spec.Schema
sch.Typed(val.Type, val.Format)
rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(sch), true)
if assert.NoError(t, err) {
assert.True(t, rt.IsArray)
}
}
// primitives and string formats
for _, val := range schTypeVals {
sch := new(spec.Schema)
sch.Typed(val.Type, val.Format)
sch.Extensions = make(spec.Extensions)
sch.Extensions["x-isnullable"] = true
rt, err := resolver.ResolveSchema(sch, true)
if assert.NoError(t, err) {
assert.True(t, rt.IsNullable, "expected %q (%q) to be nullable", val.Type, val.Format)
assertPrimitiveResolve(t, val.Type, val.Format, val.Expected, rt)
}
}
// arrays of primitives and string formats
for _, val := range schTypeVals {
var sch spec.Schema
sch.Typed(val.Type, val.Format)
sch.AddExtension("x-isnullable", true)
rt, err := resolver.ResolveSchema(new(spec.Schema).CollectionOf(sch), true)
if assert.NoError(t, err) {
assert.True(t, rt.IsArray)
}
}
}
}