Skip to content

Commit 3a68def

Browse files
committed
Add support for common parameters
1 parent 91bb667 commit 3a68def

File tree

6 files changed

+494
-78
lines changed

6 files changed

+494
-78
lines changed

internal/explorer/config_explorer.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,18 @@ func (e configExplorer) FindResources() (map[string]Resource, error) {
8181
continue
8282
}
8383

84+
parameters, err := extractParameters(e.spec.Paths, resourceConfig.Read.Path)
85+
if err != nil {
86+
errResult = errors.Join(errResult, fmt.Errorf("failed to extract '%s.delete': %w", name, err))
87+
continue
88+
}
89+
8490
resources[name] = Resource{
8591
CreateOp: createOp,
8692
ReadOp: readOp,
8793
UpdateOp: updateOp,
8894
DeleteOp: deleteOp,
95+
Parameters: parameters,
8996
SchemaOptions: extractSchemaOptions(resourceConfig.SchemaOptions),
9097
}
9198
}
@@ -103,8 +110,16 @@ func (e configExplorer) FindDataSources() (map[string]DataSource, error) {
103110
errResult = errors.Join(errResult, fmt.Errorf("failed to extract '%s.read': %w", name, err))
104111
continue
105112
}
113+
114+
parameters, err := extractParameters(e.spec.Paths, dataSourceConfig.Read.Path)
115+
if err != nil {
116+
errResult = errors.Join(errResult, fmt.Errorf("failed to extract '%s.delete': %w", name, err))
117+
continue
118+
}
119+
106120
dataSources[name] = DataSource{
107121
ReadOp: readOp,
122+
Parameters: parameters,
108123
SchemaOptions: extractSchemaOptions(dataSourceConfig.SchemaOptions),
109124
}
110125
}
@@ -145,6 +160,17 @@ func extractOp(paths *high.Paths, oasLocation *config.OpenApiSpecLocation) (*hig
145160
}
146161
}
147162

163+
func extractParameters(paths *high.Paths, path string) ([]*high.Parameter, error) {
164+
// No need to search OAS if not defined
165+
if paths.PathItems.GetOrZero(path) == nil {
166+
return nil, fmt.Errorf("path '%s' not found in OpenAPI spec", path)
167+
}
168+
169+
pathItem, _ := paths.PathItems.Get(path)
170+
171+
return pathItem.Parameters, nil
172+
}
173+
148174
func extractSchemaProxy(document high.Document, componentRef string) (*highbase.SchemaProxy, error) {
149175
// find the reference using the root document.Index
150176
indexRef := document.Index.FindComponentInRoot(componentRef)

0 commit comments

Comments
 (0)