@@ -97,6 +97,11 @@ func (c *codeConfig) Collect() error {
97
97
return nil
98
98
}
99
99
100
+ type apiHandler struct {
101
+ worker * v1.ApiWorker
102
+ target string
103
+ }
104
+
100
105
// apiSpec produces an open api v3 spec for the requests API name
101
106
func (c * codeConfig ) apiSpec (api string ) (* openapi3.T , error ) {
102
107
doc := & openapi3.T {
@@ -111,11 +116,16 @@ func (c *codeConfig) apiSpec(api string) (*openapi3.T, error) {
111
116
doc .OpenAPI = "3.0.1"
112
117
113
118
// Compile an API specification from the functions in the stack for the given API name
114
- workers := make ([]* v1. ApiWorker , 0 )
119
+ workers := make ([]* apiHandler , 0 )
115
120
116
121
// Collect all workers
117
- for _ , f := range c .functions {
118
- workers = append (workers , f .apis [api ].workers ... )
122
+ for handler , f := range c .functions {
123
+ for _ , w := range f .apis [api ].workers {
124
+ workers = append (workers , & apiHandler {
125
+ target : containerNameFromHandler (handler ),
126
+ worker : w ,
127
+ })
128
+ }
119
129
}
120
130
121
131
// loop over workers to build new api specification
@@ -124,7 +134,7 @@ func (c *codeConfig) apiSpec(api string) (*openapi3.T, error) {
124
134
for _ , w := range workers {
125
135
params := make (openapi3.Parameters , 0 )
126
136
normalizedPath := ""
127
- for _ , p := range strings .Split (w .Path , "/" ) {
137
+ for _ , p := range strings .Split (w .worker . Path , "/" ) {
128
138
if strings .HasPrefix (p , ":" ) {
129
139
paramName := strings .Replace (p , ":" , "" , - 1 )
130
140
params = append (params , & openapi3.ParameterRef {
@@ -150,18 +160,25 @@ func (c *codeConfig) apiSpec(api string) (*openapi3.T, error) {
150
160
doc .Paths [normalizedPath ] = pathItem
151
161
}
152
162
153
- for _ , m := range w .Methods {
163
+ for _ , m := range w .worker . Methods {
154
164
if pathItem .Operations () != nil && pathItem .Operations ()[m ] != nil {
155
165
// If the operation already exists we should fail
156
166
// NOTE: This should not happen as operations are stored in a map
157
167
// in the api state for functions
158
168
return nil , fmt .Errorf ("found conflicting operations" )
159
169
}
160
170
161
- // See if the path already exists
162
171
doc .AddOperation (normalizedPath , m , & openapi3.Operation {
163
172
OperationID : normalizedPath + m ,
164
173
Responses : openapi3 .NewResponses (),
174
+ ExtensionProps : openapi3.ExtensionProps {
175
+ Extensions : map [string ]interface {}{
176
+ "x-nitric-target" : map [string ]interface {}{
177
+ "type" : "function" ,
178
+ "name" : containerNameFromHandler (w .target ),
179
+ },
180
+ },
181
+ },
165
182
})
166
183
}
167
184
}
0 commit comments