Skip to content

Commit 1cb875a

Browse files
committed
feat: Populate api documents when loading stack from file.
fail if documents cannot be found
1 parent b5271d3 commit 1cb875a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/stack/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"path"
2222
"path/filepath"
2323

24+
"github.com/getkin/kin-openapi/openapi3"
2425
"gopkg.in/yaml.v2"
2526
)
2627

@@ -139,6 +140,7 @@ type Stack struct {
139140
Topics map[string]interface{} `yaml:"topics,omitempty"`
140141
Queues map[string]interface{} `yaml:"queues,omitempty"`
141142
Schedules map[string]Schedule `yaml:"schedules,omitempty"`
143+
apiDocs map[string]*openapi3.T `yaml:"-"`
142144
Apis map[string]string `yaml:"apis,omitempty"`
143145
Sites map[string]Site `yaml:"sites,omitempty"`
144146
EntryPoints map[string]Entrypoint `yaml:"entrypoints,omitempty"`
@@ -177,6 +179,15 @@ func FromFile(name string) (*Stack, error) {
177179
stack.Containers[name] = c
178180
}
179181

182+
// Attempt to populate documents from api file references
183+
for k, v := range stack.Apis {
184+
if doc, err := openapi3.NewLoader().LoadFromFile(filepath.Join(stack.dir, v)); err != nil {
185+
return nil, err
186+
} else {
187+
stack.apiDocs[k] = doc
188+
}
189+
}
190+
180191
return stack, nil
181192
}
182193

0 commit comments

Comments
 (0)