本文整理匯總了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)
}
}
}
}