本文整理匯總了Golang中github.com/vikstrous/go-swagger/spec.Document.Spec方法的典型用法代碼示例。如果您正苦於以下問題:Golang Document.Spec方法的具體用法?Golang Document.Spec怎麽用?Golang Document.Spec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vikstrous/go-swagger/spec.Document
的用法示例。
在下文中一共展示了Document.Spec方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: gatherModels
func gatherModels(specDoc *spec.Document, modelNames []string) map[string]spec.Schema {
models, mnc := make(map[string]spec.Schema), len(modelNames)
for k, v := range specDoc.Spec().Definitions {
for _, nm := range modelNames {
if mnc == 0 || k == nm {
models[k] = v
}
}
}
return models
}
示例2: Validate
// Validate validates the swagger spec
func (s *SpecValidator) Validate(data interface{}) (errs *Result, warnings *Result) {
var sd *spec.Document
switch v := data.(type) {
case *spec.Document:
sd = v
}
if sd == nil {
errs = sErr(errors.New(500, "spec validator can only validate spec.Document objects"))
return
}
s.spec = sd
errs = new(Result)
warnings = new(Result)
schv := NewSchemaValidator(s.schema, nil, "", s.KnownFormats)
errs.Merge(schv.Validate(sd.Spec())) // error -
if errs.HasErrors() {
return // no point in continuing
}
errs.Merge(s.validateReferencesValid()) // error -
if errs.HasErrors() {
return // no point in continuing
}
errs.Merge(s.validateDuplicatePropertyNames()) // error -
errs.Merge(s.validateParameters()) // error -
errs.Merge(s.validateItems()) // error -
errs.Merge(s.validateRequiredDefinitions()) // error -
errs.Merge(s.validateDefaultValueValidAgainstSchema()) // error -
errs.Merge(s.validateExamplesValidAgainstSchema()) // error -
warnings.Merge(s.validateUniqueSecurityScopes()) // warning
warnings.Merge(s.validateUniqueScopesSecurityDefinitions()) // warning
warnings.Merge(s.validateReferenced()) // warning
return
}
示例3: appNameOrDefault
func appNameOrDefault(specDoc *spec.Document, name, defaultName string) string {
if name == "" {
if specDoc.Spec().Info != nil && specDoc.Spec().Info.Title != "" {
name = specDoc.Spec().Info.Title
} else {
name = defaultName
}
}
return swag.ToGoName(name)
}