Skip to content

Commit

Permalink
Fix problem preventing support for vendor extensions at the top level…
Browse files Browse the repository at this point in the history
… of specifications.
  • Loading branch information
timburks committed Dec 16, 2016
1 parent 7d27e76 commit acf8307
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 189 deletions.
26 changes: 24 additions & 2 deletions OpenAPIv2/OpenAPIv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ func NewDocument(in interface{}, context *helpers.Context) (*Document, error) {
errors = append(errors, helpers.NewError(context, "does not contain all required properties ('info','paths','swagger')"))
}
allowedKeys := []string{"basePath", "consumes", "definitions", "externalDocs", "host", "info", "parameters", "paths", "produces", "responses", "schemes", "security", "securityDefinitions", "swagger", "tags"}
allowedPatterns := []string{}
allowedPatterns := []string{"^x-"}
if !helpers.MapContainsOnlyKeysAndPatterns(m, allowedKeys, allowedPatterns) {
errors = append(errors, helpers.NewError(context,
fmt.Sprintf("includes properties not in ('basePath','consumes','definitions','externalDocs','host','info','parameters','paths','produces','responses','schemes','security','securityDefinitions','swagger','tags') or (): %+v",
fmt.Sprintf("includes properties not in ('basePath','consumes','definitions','externalDocs','host','info','parameters','paths','produces','responses','schemes','security','securityDefinitions','swagger','tags') or ('^x-'): %+v",
helpers.SortedKeysForMap(m))))
}
x := &Document{}
Expand Down Expand Up @@ -564,6 +564,23 @@ func NewDocument(in interface{}, context *helpers.Context) (*Document, error) {
errors = append(errors, err)
}
}
// repeated NamedAny vendor_extension = 16;
// MAP: Any ^x-
x.VendorExtension = make([]*NamedAny, 0)
for _, item := range m {
k := item.Key.(string)
v := item.Value
if helpers.PatternMatches("^x-", k) {
pair := &NamedAny{}
pair.Name = k
var err error
pair.Value, err = NewAny(v, helpers.NewContext(k, context))
if err != nil {
return nil, err
}
x.VendorExtension = append(x.VendorExtension, pair)
}
}
if len(errors) > 0 {
return x, helpers.NewErrorGroup(errors)
} else {
Expand Down Expand Up @@ -4242,6 +4259,11 @@ func (m *Document) ResolveReferences(root string) (interface{}, error) {
if m.ExternalDocs != nil {
m.ExternalDocs.ResolveReferences(root)
}
for _, item := range m.VendorExtension {
if item != nil {
item.ResolveReferences(root)
}
}
return nil, nil
}

Expand Down

0 comments on commit acf8307

Please sign in to comment.