本文整理匯總了Golang中github.com/go-openapi/spec.Schema.Items方法的典型用法代碼示例。如果您正苦於以下問題:Golang Schema.Items方法的具體用法?Golang Schema.Items怎麽用?Golang Schema.Items使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-openapi/spec.Schema
的用法示例。
在下文中一共展示了Schema.Items方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestTypeResolver_AdditionalItems
func TestTypeResolver_AdditionalItems(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
tpe := spec.StringProperty()
if assert.NoError(t, err) {
// arrays of primitives and string formats with additional formats
for _, val := range schTypeVals {
var sch spec.Schema
sch.Typed(val.Type, val.Format)
var coll spec.Schema
coll.Type = []string{"array"}
coll.Items = new(spec.SchemaOrArray)
coll.Items.Schema = tpe
coll.AdditionalItems = new(spec.SchemaOrBool)
coll.AdditionalItems.Schema = &sch
rt, err := resolver.ResolveSchema(&coll, true, true)
if assert.NoError(t, err) && assert.True(t, rt.IsArray) {
assert.True(t, rt.HasAdditionalItems)
assert.False(t, rt.IsNullable)
//if assert.NotNil(t, rt.ElementType) {
//assertPrimitiveResolve(t, "string", "", "string", *rt.ElementType)
//}
}
}
}
}
示例2: bodyTypable
func bodyTypable(in string, schema *spec.Schema) (swaggerTypable, *spec.Schema) {
if in == "body" {
// get the schema for items on the schema property
if schema == nil {
schema = new(spec.Schema)
}
if schema.Items == nil {
schema.Items = new(spec.SchemaOrArray)
}
if schema.Items.Schema == nil {
schema.Items.Schema = new(spec.Schema)
}
schema.Typed("array", "")
return schemaTypable{schema.Items.Schema, 0}, schema
}
return nil, nil
}
示例3: TestTypeResolver_TupleTypes
func TestTypeResolver_TupleTypes(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
if assert.NoError(t, err) {
// tuple type (items with multiple schemas)
parent := new(spec.Schema)
parent.Typed("array", "")
parent.Items = new(spec.SchemaOrArray)
parent.Items.Schemas = append(
parent.Items.Schemas,
*spec.StringProperty(),
*spec.Int64Property(),
*spec.Float64Property(),
*spec.BoolProperty(),
*spec.ArrayProperty(spec.StringProperty()),
*spec.RefProperty("#/definitions/Comment"),
)
rt, err := resolver.ResolveSchema(parent, true, true)
if assert.NoError(t, err) {
assert.False(t, rt.IsArray)
assert.True(t, rt.IsTuple)
}
}
}