本文整理匯總了Golang中github.com/go-openapi/spec.Schema.Ref方法的典型用法代碼示例。如果您正苦於以下問題:Golang Schema.Ref方法的具體用法?Golang Schema.Ref怎麽用?Golang Schema.Ref使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-openapi/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 {
switch st := ts.Type.(type) {
case *ast.StructType:
return scp.parseStructType(file, schema, st, seenPreviously)
case *ast.InterfaceType:
return scp.parseInterfaceType(file, schema, st, seenPreviously)
}
}
return nil
}