added path items to components.

I don’t know how I missed this.

I don’t know how someone has not complained about it.
This commit is contained in:
quobix
2024-08-07 14:21:58 -04:00
parent fb545f9584
commit 07ff746732
4 changed files with 30 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ type Components struct {
SecuritySchemes *orderedmap.Map[string, *SecurityScheme] `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"` SecuritySchemes *orderedmap.Map[string, *SecurityScheme] `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
Links *orderedmap.Map[string, *Link] `json:"links,omitempty" yaml:"links,omitempty"` Links *orderedmap.Map[string, *Link] `json:"links,omitempty" yaml:"links,omitempty"`
Callbacks *orderedmap.Map[string, *Callback] `json:"callbacks,omitempty" yaml:"callbacks,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:"-"` Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"`
low *low.Components low *low.Components
} }
@@ -51,12 +52,13 @@ func NewComponents(comp *low.Components) *Components {
exampleMap := orderedmap.New[string, *highbase.Example]() exampleMap := orderedmap.New[string, *highbase.Example]()
requestBodyMap := orderedmap.New[string, *RequestBody]() requestBodyMap := orderedmap.New[string, *RequestBody]()
headerMap := orderedmap.New[string, *Header]() headerMap := orderedmap.New[string, *Header]()
pathItemMap := orderedmap.New[string, *PathItem]()
securitySchemeMap := orderedmap.New[string, *SecurityScheme]() securitySchemeMap := orderedmap.New[string, *SecurityScheme]()
schemas := orderedmap.New[string, *highbase.SchemaProxy]() schemas := orderedmap.New[string, *highbase.SchemaProxy]()
// build all components asynchronously. // build all components asynchronously.
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(9) wg.Add(10)
go func() { go func() {
buildComponent[*low.Callback, *Callback](comp.Callbacks.Value, cbMap, NewCallback) buildComponent[*low.Callback, *Callback](comp.Callbacks.Value, cbMap, NewCallback)
wg.Done() wg.Done()
@@ -85,6 +87,10 @@ func NewComponents(comp *low.Components) *Components {
buildComponent[*low.Header, *Header](comp.Headers.Value, headerMap, NewHeader) buildComponent[*low.Header, *Header](comp.Headers.Value, headerMap, NewHeader)
wg.Done() wg.Done()
}() }()
go func() {
buildComponent[*low.PathItem, *PathItem](comp.PathItems.Value, pathItemMap, NewPathItem)
wg.Done()
}()
go func() { go func() {
buildComponent[*low.SecurityScheme, *SecurityScheme](comp.SecuritySchemes.Value, securitySchemeMap, NewSecurityScheme) buildComponent[*low.SecurityScheme, *SecurityScheme](comp.SecuritySchemes.Value, securitySchemeMap, NewSecurityScheme)
wg.Done() wg.Done()
@@ -104,6 +110,7 @@ func NewComponents(comp *low.Components) *Components {
c.RequestBodies = requestBodyMap c.RequestBodies = requestBodyMap
c.Examples = exampleMap c.Examples = exampleMap
c.SecuritySchemes = securitySchemeMap c.SecuritySchemes = securitySchemeMap
c.PathItems = pathItemMap
return c return c
} }

View File

@@ -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() dat, _ := comp.Render()
@@ -64,7 +71,11 @@ requestBodies:
body: body:
content: content:
application/json: application/json:
example: why?` example: why?
pathItems:
/ding/dong/{bing}/{bong}/go:
get:
description: get`
dat, _ = r.Render() dat, _ = r.Render()
assert.Equal(t, desired, strings.TrimSpace(string(dat))) assert.Equal(t, desired, strings.TrimSpace(string(dat)))

View File

@@ -35,6 +35,7 @@ type Components struct {
SecuritySchemes low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*SecurityScheme]]] SecuritySchemes low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*SecurityScheme]]]
Links low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*Link]]] Links low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*Link]]]
Callbacks low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*Callback]]] 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]] Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
KeyNode *yaml.Node KeyNode *yaml.Node
RootNode *yaml.Node RootNode *yaml.Node
@@ -79,6 +80,7 @@ func (co *Components) Hash() [32]byte {
generateHashForObjectMap(co.SecuritySchemes.Value, &f) generateHashForObjectMap(co.SecuritySchemes.Value, &f)
generateHashForObjectMap(co.Links.Value, &f) generateHashForObjectMap(co.Links.Value, &f)
generateHashForObjectMap(co.Callbacks.Value, &f) generateHashForObjectMap(co.Callbacks.Value, &f)
generateHashForObjectMap(co.PathItems.Value, &f)
f = append(f, low.HashExtensions(co.Extensions)...) f = append(f, low.HashExtensions(co.Extensions)...)
return sha256.Sum256([]byte(strings.Join(f, "|"))) return sha256.Sum256([]byte(strings.Join(f, "|")))
} }
@@ -149,7 +151,7 @@ func (co *Components) Build(ctx context.Context, root *yaml.Node, idx *index.Spe
var reterr error var reterr error
var ceMutex sync.Mutex var ceMutex sync.Mutex
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(9) wg.Add(10)
captureError := func(err error) { captureError := func(err error) {
ceMutex.Lock() ceMutex.Lock()
@@ -213,6 +215,12 @@ func (co *Components) Build(ctx context.Context, root *yaml.Node, idx *index.Spe
co.Callbacks = callbacks co.Callbacks = callbacks
wg.Done() wg.Done()
}() }()
go func() {
pathItems, err := extractComponentValues[*PathItem](ctx, PathItemsLabel, root, idx, co)
captureError(err)
co.PathItems = pathItems
wg.Done()
}()
wg.Wait() wg.Wait()
return reterr return reterr

View File

@@ -19,6 +19,7 @@ const (
CallbacksLabel = "callbacks" CallbacksLabel = "callbacks"
ContentLabel = "content" ContentLabel = "content"
PathsLabel = "paths" PathsLabel = "paths"
PathItemsLabel = "pathItems"
PathLabel = "path" PathLabel = "path"
WebhooksLabel = "webhooks" WebhooksLabel = "webhooks"
JSONSchemaDialectLabel = "jsonSchemaDialect" JSONSchemaDialectLabel = "jsonSchemaDialect"