Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pathItems to components. #318

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 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 @@ -131,6 +133,10 @@ func (co *Components) FindLink(link string) *low.ValueReference[*Link] {
return low.FindItemInOrderedMap[*Link](link, co.Links.Value)
}

func (co *Components) FindPathItem(path string) *low.ValueReference[*PathItem] {
return low.FindItemInOrderedMap[*PathItem](path, co.PathItems.Value)
}

func (co *Components) FindCallback(callback string) *low.ValueReference[*Callback] {
return low.FindItemInOrderedMap[*Callback](callback, co.Callbacks.Value)
}
Expand All @@ -149,7 +155,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 +219,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
10 changes: 7 additions & 3 deletions datamodel/low/v3/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ var testComponentsYaml = `
eighteen:
'{raference}':
post:
description: eighteen of many`
description: eighteen of many
pathItems:
/nineteen:
get:
description: nineteen of many`

func TestComponents_Build_Success(t *testing.T) {
var idxNode yaml.Node
Expand Down Expand Up @@ -96,13 +100,13 @@ func TestComponents_Build_Success(t *testing.T) {
assert.Equal(t, "thirteen of many", n.FindSecurityScheme("thirteen").Value.Description.Value)
assert.Equal(t, "fourteen of many", n.FindSecurityScheme("fourteen").Value.Description.Value)
assert.Equal(t, "fifteen of many", n.FindLink("fifteen").Value.Description.Value)
assert.Equal(t, "sixteen of many", n.FindLink("sixteen").Value.Description.Value)
assert.Equal(t, "seventeen of many",
n.FindCallback("seventeen").Value.FindExpression("{reference}").Value.Post.Value.Description.Value)
assert.Equal(t, "eighteen of many",
n.FindCallback("eighteen").Value.FindExpression("{raference}").Value.Post.Value.Description.Value)
assert.Equal(t, "nineteen of many", n.FindPathItem("/nineteen").Value.Get.Value.Description.Value)

assert.Equal(t, "76328a0e32a9989471d335734af04a37bdfad333cf8cd8aa8065998c3a1489a2",
assert.Equal(t, "c3f868ba89e4c5260831e1fc99dfcacc6e7e63299430bbb88dcfffd06d633e1c",
low.GenerateHashString(&n))
}

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
Loading