本文整理汇总了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)
}