本文整理汇总了Golang中github.com/vikstrous/go-swagger/spec.Schema.AdditionalItems方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.AdditionalItems方法的具体用法?Golang Schema.AdditionalItems怎么用?Golang Schema.AdditionalItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vikstrous/go-swagger/spec.Schema
的用法示例。
在下文中一共展示了Schema.AdditionalItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
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: buildItems
func (sg *schemaGenContext) buildItems() error {
presentsAsSingle := sg.Schema.Items != nil && sg.Schema.Items.Schema != nil
if presentsAsSingle && sg.Schema.AdditionalItems != nil { // unsure if htis a valid of invalid schema
return fmt.Errorf("single schema (%s) can't have additional items", sg.Name)
}
if presentsAsSingle {
return sg.buildArray()
}
if sg.Schema.Items == nil {
return nil
}
// This is a tuple, build a new model that represents this
if sg.Named {
sg.GenSchema.Name = sg.Name
sg.GenSchema.GoType = swag.ToGoName(sg.Name)
if sg.TypeResolver.ModelsPackage != "" {
sg.GenSchema.GoType = sg.TypeResolver.ModelsPackage + "." + sg.GenSchema.GoType
}
for i, s := range sg.Schema.Items.Schemas {
elProp := sg.NewTupleElement(&s, i)
if err := elProp.makeGenSchema(); err != nil {
return err
}
sg.MergeResult(elProp)
elProp.GenSchema.Name = "p" + strconv.Itoa(i)
sg.GenSchema.Properties = append(sg.GenSchema.Properties, elProp.GenSchema)
}
return nil
}
// for an anonoymous object, first build the new object
// and then replace the current one with a $ref to the
// new tuple object
var sch spec.Schema
sch.Typed("object", "")
sch.Properties = make(map[string]spec.Schema)
for i, v := range sg.Schema.Items.Schemas {
sch.Required = append(sch.Required, "P"+strconv.Itoa(i))
sch.Properties["P"+strconv.Itoa(i)] = v
}
sch.AdditionalItems = sg.Schema.AdditionalItems
tup := sg.makeNewStruct(sg.GenSchema.Name+"Tuple"+strconv.Itoa(sg.Index), sch)
if err := tup.makeGenSchema(); err != nil {
return err
}
tup.GenSchema.IsTuple = true
tup.GenSchema.IsComplexObject = false
tup.GenSchema.Title = tup.GenSchema.Name + " a representation of an anonymous Tuple type"
tup.GenSchema.Description = ""
sg.ExtraSchemas[tup.Name] = tup.GenSchema
sg.Schema = *spec.RefProperty("#/definitions/" + tup.Name)
if err := sg.makeGenSchema(); err != nil {
return err
}
sg.MergeResult(tup)
return nil
}