Skip to content

Commit

Permalink
added path items to components.
Browse files Browse the repository at this point in the history
I don’t know how I missed this.

I don’t know how someone has not complained about it.
  • Loading branch information
daveshanley committed Aug 7, 2024
1 parent 61b8a2f commit 226d1df
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
9 changes: 8 additions & 1 deletion datamodel/high/v3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Components struct {
SecuritySchemes *orderedmap.Map[string, *SecurityScheme] `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
Links *orderedmap.Map[string, *Link] `json:"links,omitempty" yaml:"links,omitempty"`
Callbacks *orderedmap.Map[string, *Callback] `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
PathItems *orderedmap.Map[string, *PathItem] `json:"pathItems,omitempty" yaml:"pathItems,omitempty"`
Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"`
low *low.Components
}
Expand All @@ -51,12 +52,13 @@ func NewComponents(comp *low.Components) *Components {
exampleMap := orderedmap.New[string, *highbase.Example]()
requestBodyMap := orderedmap.New[string, *RequestBody]()
headerMap := orderedmap.New[string, *Header]()
pathItemMap := orderedmap.New[string, *PathItem]()
securitySchemeMap := orderedmap.New[string, *SecurityScheme]()
schemas := orderedmap.New[string, *highbase.SchemaProxy]()

// build all components asynchronously.
var wg sync.WaitGroup
wg.Add(9)
wg.Add(10)
go func() {
buildComponent[*low.Callback, *Callback](comp.Callbacks.Value, cbMap, NewCallback)
wg.Done()
Expand Down Expand Up @@ -85,6 +87,10 @@ func NewComponents(comp *low.Components) *Components {
buildComponent[*low.Header, *Header](comp.Headers.Value, headerMap, NewHeader)
wg.Done()
}()
go func() {
buildComponent[*low.PathItem, *PathItem](comp.PathItems.Value, pathItemMap, NewPathItem)
wg.Done()
}()
go func() {
buildComponent[*low.SecurityScheme, *SecurityScheme](comp.SecuritySchemes.Value, securitySchemeMap, NewSecurityScheme)
wg.Done()
Expand All @@ -104,6 +110,7 @@ func NewComponents(comp *low.Components) *Components {
c.RequestBodies = requestBodyMap
c.Examples = exampleMap
c.SecuritySchemes = securitySchemeMap
c.PathItems = pathItemMap
return c
}

Expand Down
13 changes: 12 additions & 1 deletion datamodel/high/v3/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func TestComponents_MarshalYAML(t *testing.T) {
}),
},
}),
PathItems: orderedmap.ToOrderedMap(map[string]*PathItem{
"/ding/dong/{bing}/{bong}/go": {
Get: &Operation{
Description: "get",
},
},
}),
}

dat, _ := comp.Render()
Expand All @@ -64,7 +71,11 @@ requestBodies:
body:
content:
application/json:
example: why?`
example: why?
pathItems:
/ding/dong/{bing}/{bong}/go:
get:
description: get`

dat, _ = r.Render()
assert.Equal(t, desired, strings.TrimSpace(string(dat)))
Expand Down
10 changes: 9 additions & 1 deletion datamodel/low/v3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Components struct {
SecuritySchemes low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*SecurityScheme]]]
Links low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*Link]]]
Callbacks low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*Callback]]]
PathItems low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*PathItem]]]
Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
KeyNode *yaml.Node
RootNode *yaml.Node
Expand Down Expand Up @@ -79,6 +80,7 @@ func (co *Components) Hash() [32]byte {
generateHashForObjectMap(co.SecuritySchemes.Value, &f)
generateHashForObjectMap(co.Links.Value, &f)
generateHashForObjectMap(co.Callbacks.Value, &f)
generateHashForObjectMap(co.PathItems.Value, &f)
f = append(f, low.HashExtensions(co.Extensions)...)
return sha256.Sum256([]byte(strings.Join(f, "|")))
}
Expand Down Expand Up @@ -149,7 +151,7 @@ func (co *Components) Build(ctx context.Context, root *yaml.Node, idx *index.Spe
var reterr error
var ceMutex sync.Mutex
var wg sync.WaitGroup
wg.Add(9)
wg.Add(10)

captureError := func(err error) {
ceMutex.Lock()
Expand Down Expand Up @@ -213,6 +215,12 @@ func (co *Components) Build(ctx context.Context, root *yaml.Node, idx *index.Spe
co.Callbacks = callbacks
wg.Done()
}()
go func() {
pathItems, err := extractComponentValues[*PathItem](ctx, PathItemsLabel, root, idx, co)
captureError(err)
co.PathItems = pathItems
wg.Done()
}()

wg.Wait()
return reterr
Expand Down
1 change: 1 addition & 0 deletions datamodel/low/v3/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
CallbacksLabel = "callbacks"
ContentLabel = "content"
PathsLabel = "paths"
PathItemsLabel = "pathItems"
PathLabel = "path"
WebhooksLabel = "webhooks"
JSONSchemaDialectLabel = "jsonSchemaDialect"
Expand Down

0 comments on commit 226d1df

Please sign in to comment.