mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
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:
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
@@ -104,6 +110,7 @@ func NewComponents(comp *low.Components) *Components {
|
||||
c.RequestBodies = requestBodyMap
|
||||
c.Examples = exampleMap
|
||||
c.SecuritySchemes = securitySchemeMap
|
||||
c.PathItems = pathItemMap
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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)))
|
||||
|
||||
@@ -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
|
||||
@@ -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, "|")))
|
||||
}
|
||||
@@ -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()
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,7 @@ const (
|
||||
CallbacksLabel = "callbacks"
|
||||
ContentLabel = "content"
|
||||
PathsLabel = "paths"
|
||||
PathItemsLabel = "pathItems"
|
||||
PathLabel = "path"
|
||||
WebhooksLabel = "webhooks"
|
||||
JSONSchemaDialectLabel = "jsonSchemaDialect"
|
||||
|
||||
Reference in New Issue
Block a user