diff --git a/datamodel/high/v3/components.go b/datamodel/high/v3/components.go index e5d6c1e3..0ea599f3 100644 --- a/datamodel/high/v3/components.go +++ b/datamodel/high/v3/components.go @@ -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 } diff --git a/datamodel/high/v3/components_test.go b/datamodel/high/v3/components_test.go index 4e920816..68330d54 100644 --- a/datamodel/high/v3/components_test.go +++ b/datamodel/high/v3/components_test.go @@ -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))) diff --git a/datamodel/low/v3/components.go b/datamodel/low/v3/components.go index 75a7c424..04ca980b 100644 --- a/datamodel/low/v3/components.go +++ b/datamodel/low/v3/components.go @@ -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 diff --git a/datamodel/low/v3/constants.go b/datamodel/low/v3/constants.go index 6d0a0d00..07897e7d 100644 --- a/datamodel/low/v3/constants.go +++ b/datamodel/low/v3/constants.go @@ -19,6 +19,7 @@ const ( CallbacksLabel = "callbacks" ContentLabel = "content" PathsLabel = "paths" + PathItemsLabel = "pathItems" PathLabel = "path" WebhooksLabel = "webhooks" JSONSchemaDialectLabel = "jsonSchemaDialect"