本文整理汇总了Golang中github.com/vikstrous/go-swagger/spec.Schema.Ref方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.Ref方法的具体用法?Golang Schema.Ref怎么用?Golang Schema.Ref使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vikstrous/go-swagger/spec.Schema
的用法示例。
在下文中一共展示了Schema.Ref方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseAllOfMember
func (scp *schemaParser) parseAllOfMember(gofile *ast.File, schema *spec.Schema, expr ast.Expr, seenPreviously map[string]struct{}) error {
// TODO: check if struct is annotated with swagger:model or known in the definitions otherwise
var pkg *loader.PackageInfo
var file *ast.File
var gd *ast.GenDecl
var ts *ast.TypeSpec
var err error
switch tpe := expr.(type) {
case *ast.Ident:
// do lookup of type
// take primitives into account, they should result in an error for swagger
pkg, err = scp.packageForFile(gofile)
if err != nil {
return err
}
file, gd, ts, err = findSourceFile(pkg, tpe.Name)
if err != nil {
return err
}
case *ast.SelectorExpr:
// look up package, file and then type
pkg, err = scp.packageForSelector(gofile, tpe.X)
if err != nil {
return fmt.Errorf("embedded struct: %v", err)
}
file, gd, ts, err = findSourceFile(pkg, tpe.Sel.Name)
if err != nil {
return fmt.Errorf("embedded struct: %v", err)
}
default:
return fmt.Errorf("unable to resolve allOf member for: %v\n", expr)
}
sd := newSchemaDecl(file, gd, ts)
if sd.hasAnnotation() {
ref, err := spec.NewRef("#/definitions/" + sd.Name)
if err != nil {
return err
}
schema.Ref = ref
scp.postDecls = append(scp.postDecls, *sd)
} else {
if st, ok := ts.Type.(*ast.StructType); ok {
return scp.parseStructType(file, schema, st, seenPreviously)
}
}
return nil
}