Skip to content

Commit ae59662

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 32583e7 + 3046ef0 commit ae59662

33 files changed

Lines changed: 1366 additions & 1298 deletions

api/handler_fileserver_test.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api_test
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/require"
65
"mokapi/api"
76
"mokapi/config/dynamic"
87
"mokapi/config/static"
@@ -14,6 +13,8 @@ import (
1413
"net/url"
1514
"strings"
1615
"testing"
16+
17+
"github.com/stretchr/testify/require"
1718
)
1819

1920
func TestHandler_FileServer(t *testing.T) {
@@ -168,7 +169,7 @@ func TestOpenGraphInDashboard(t *testing.T) {
168169
app := runtime.New(cfg)
169170
app.AddHttp(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
170171
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
171-
openapitest.WithPath("/pet/{petId}", openapitest.NewPath()),
172+
openapitest.WithPath("/pet/{petId}"),
172173
)},
173174
)
174175
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
@@ -192,9 +193,9 @@ func TestOpenGraphInDashboard(t *testing.T) {
192193
app := runtime.New(cfg)
193194
app.AddHttp(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
194195
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
195-
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
196+
openapitest.WithPath("/pet/{petId}",
196197
openapitest.WithPathInfo("foo", "bar"),
197-
)),
198+
),
198199
),
199200
})
200201
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
@@ -218,9 +219,9 @@ func TestOpenGraphInDashboard(t *testing.T) {
218219
app := runtime.New(cfg)
219220
app.AddHttp(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
220221
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
221-
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
222+
openapitest.WithPath("/pet/{petId}",
222223
openapitest.WithPathInfo("", "bar"),
223-
))),
224+
)),
224225
})
225226
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
226227
try.Handler(t,
@@ -243,9 +244,9 @@ func TestOpenGraphInDashboard(t *testing.T) {
243244
app := runtime.New(cfg)
244245
app.AddHttp(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
245246
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
246-
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
247-
openapitest.WithOperation("GET", openapitest.NewOperation()),
248-
))),
247+
openapitest.WithPath("/pet/{petId}",
248+
openapitest.WithOperation("GET"),
249+
)),
249250
})
250251
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
251252
try.Handler(t,
@@ -268,12 +269,13 @@ func TestOpenGraphInDashboard(t *testing.T) {
268269
app := runtime.New(cfg)
269270
app.AddHttp(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
270271
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
271-
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
272-
openapitest.WithOperation("GET", openapitest.NewOperation()),
273-
)),
274-
openapitest.WithPath("/pet/{petId}/foo", openapitest.NewPath(
275-
openapitest.WithOperation("GET", openapitest.NewOperation()),
276-
))),
272+
openapitest.WithPath("/pet/{petId}",
273+
openapitest.WithOperation("GET"),
274+
),
275+
openapitest.WithPath("/pet/{petId}/foo",
276+
openapitest.WithOperation("GET"),
277+
),
278+
),
277279
})
278280
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
279281
try.Handler(t,

api/handler_http_test.go

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ func TestHandler_Http(t *testing.T) {
111111
return runtimetest.NewHttpApp(
112112
openapitest.NewConfig("3.0.0",
113113
openapitest.WithInfo("foo", "", ""),
114-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
114+
openapitest.WithPath("/foo/{bar}",
115115
openapitest.WithPathParam("bar", openapitest.WithParamSchema(schematest.New("string"))),
116-
openapitest.WithOperation("get", openapitest.NewOperation()),
117-
)),
116+
openapitest.WithOperation("get"),
117+
),
118118
),
119119
)
120120
},
@@ -127,13 +127,13 @@ func TestHandler_Http(t *testing.T) {
127127
return runtimetest.NewHttpApp(
128128
openapitest.NewConfig("3.0.0",
129129
openapitest.WithInfo("foo", "", ""),
130-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
131-
openapitest.WithOperation("get", openapitest.NewOperation(
130+
openapitest.WithPath("/foo/{bar}",
131+
openapitest.WithOperation("get",
132132
openapitest.WithRequestBody("foo", true,
133133
openapitest.WithRequestContent("application/json", openapitest.NewContent(openapitest.WithSchema(schematest.New("string")))),
134134
),
135-
)),
136-
))),
135+
),
136+
)),
137137
)
138138
},
139139
requestUrl: "http://foo.api/api/services/http/foo",
@@ -145,11 +145,11 @@ func TestHandler_Http(t *testing.T) {
145145
return runtimetest.NewHttpApp(
146146
openapitest.NewConfig("3.0.0",
147147
openapitest.WithInfo("foo", "", ""),
148-
openapitest.WithPath("/foo", openapitest.NewPath(
149-
openapitest.WithOperation("get", openapitest.NewOperation(
148+
openapitest.WithPath("/foo",
149+
openapitest.WithOperation("get",
150150
openapitest.WithSecurity(map[string][]string{"foo": {}}),
151-
)),
152-
)),
151+
),
152+
),
153153
openapitest.WithComponentSecurity("foo", &openapi.ApiKeySecurityScheme{
154154
Type: "apiKey",
155155
In: "header",
@@ -168,9 +168,9 @@ func TestHandler_Http(t *testing.T) {
168168
openapitest.NewConfig("3.0.0",
169169
openapitest.WithGlobalSecurity(map[string][]string{"foo": {}}),
170170
openapitest.WithInfo("foo", "", ""),
171-
openapitest.WithPath("/foo", openapitest.NewPath(
172-
openapitest.WithOperation("get", openapitest.NewOperation()),
173-
)),
171+
openapitest.WithPath("/foo",
172+
openapitest.WithOperation("get"),
173+
),
174174
openapitest.WithComponentSecurity("foo", &openapi.ApiKeySecurityScheme{
175175
Type: "apiKey",
176176
In: "header",
@@ -188,20 +188,17 @@ func TestHandler_Http(t *testing.T) {
188188
return runtimetest.NewHttpApp(
189189
openapitest.NewConfig("3.0.0",
190190
openapitest.WithInfo("foo", "", ""),
191-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
192-
openapitest.WithOperation("get", openapitest.NewOperation(
191+
openapitest.WithPath("/foo/{bar}",
192+
openapitest.WithOperation("get",
193193
openapitest.WithResponse(http.StatusOK,
194194
openapitest.WithResponseDescription("foo description"),
195195
openapitest.WithContent(
196-
"application/json",
197-
openapitest.NewContent(
198-
openapitest.WithSchema(schematest.New("string")),
199-
),
200-
),
196+
"application/json", openapitest.WithSchema(schematest.New("string"))),
201197
openapitest.WithResponseHeader("foo", "bar", schematest.New("string")),
202198
),
203-
)),
204-
))),
199+
),
200+
),
201+
),
205202
)
206203
},
207204
requestUrl: "http://foo.api/api/services/http/foo",
@@ -220,25 +217,22 @@ func TestHandler_Http(t *testing.T) {
220217
},
221218
Value: openapitest.NewPath(
222219
openapitest.WithPathInfo("foo", "bar"),
223-
openapitest.WithOperation("get", openapitest.NewOperation(
224-
openapitest.WithResponseRef(http.StatusOK,
220+
openapitest.WithOperation("get",
221+
openapitest.UseResponseRef(http.StatusOK,
225222
&openapi.ResponseRef{
226223
Reference: dynamic.Reference{
227224
Ref: "#/components/pathItems/foo",
228225
Description: "Description",
229226
},
230227
Value: openapitest.NewResponse(openapitest.WithResponseDescription("foo description"),
231228
openapitest.WithContent(
232-
"application/json",
233-
openapitest.NewContent(
234-
openapitest.WithSchema(schematest.New("string")),
235-
),
229+
"application/json", openapitest.WithSchema(schematest.New("string")),
236230
),
237231
openapitest.WithResponseHeader("foo", "bar", schematest.New("string")),
238232
),
239233
},
240234
),
241-
)),
235+
),
242236
),
243237
}),
244238
)
@@ -254,19 +248,17 @@ func TestHandler_Http(t *testing.T) {
254248
return runtimetest.NewHttpApp(
255249
openapitest.NewConfig("3.0.0",
256250
openapitest.WithInfo("foo", "", ""),
257-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
258-
openapitest.WithOperation("get", openapitest.NewOperation(
251+
openapitest.WithPath("/foo/{bar}",
252+
openapitest.WithOperation("get",
259253
openapitest.WithResponse(http.StatusOK,
260254
openapitest.WithResponseDescription("foo description"),
261255
openapitest.WithContent(
262-
"application/json",
263-
openapitest.NewContent(
264-
openapitest.WithSchema(schematest.New("string", schematest.And("number"))),
265-
),
256+
"application/json", openapitest.WithSchema(schematest.New("string", schematest.And("number"))),
266257
),
267258
),
268-
)),
269-
))),
259+
),
260+
),
261+
),
270262
)
271263
},
272264
requestUrl: "http://foo.api/api/services/http/foo",
@@ -278,19 +270,16 @@ func TestHandler_Http(t *testing.T) {
278270
return runtimetest.NewHttpApp(
279271
openapitest.NewConfig("3.0.0",
280272
openapitest.WithInfo("foo", "", ""),
281-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
282-
openapitest.WithOperation("get", openapitest.NewOperation(
273+
openapitest.WithPath("/foo/{bar}",
274+
openapitest.WithOperation("get",
283275
openapitest.WithResponse(http.StatusOK,
284276
openapitest.WithResponseDescription("foo description"),
285277
openapitest.WithContent(
286-
"application/json",
287-
openapitest.NewContent(
288-
openapitest.WithSchema(schematest.New("string", schematest.WithDefault("foobar"))),
289-
),
278+
"application/json", openapitest.WithSchema(schematest.New("string", schematest.WithDefault("foobar"))),
290279
),
291280
),
292281
)),
293-
))),
282+
),
294283
)
295284
},
296285
requestUrl: "http://foo.api/api/services/http/foo",
@@ -302,11 +291,11 @@ func TestHandler_Http(t *testing.T) {
302291
return runtimetest.NewHttpApp(
303292
openapitest.NewConfig("3.0.0",
304293
openapitest.WithInfo("foo", "", ""),
305-
openapitest.WithPath("/foo/{bar}", openapitest.NewPath(
306-
openapitest.WithOperation("get", openapitest.NewOperation(
294+
openapitest.WithPath("/foo/{bar}",
295+
openapitest.WithOperation("get",
307296
openapitest.WithTagName("foo"),
308-
)),
309-
)),
297+
),
298+
),
310299
openapitest.WithTag("foo", "sum", "desc"),
311300
),
312301
)

api/handler_schema_test.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ func TestHandler_Schema_Example_Query(t *testing.T) {
3535
app: runtimetest.NewHttpApp(openapitest.NewConfig("3.1.0",
3636
openapitest.WithInfo("foo", "", ""),
3737
openapitest.WithPath("/foo",
38-
openapitest.NewPath(openapitest.WithOperation("GET",
39-
openapitest.NewOperation(
40-
openapitest.WithResponse(200,
41-
openapitest.WithContent("application/json", openapitest.NewContent(
42-
openapitest.WithSchema(schematest.New("string")),
43-
)),
38+
openapitest.WithOperation("GET",
39+
openapitest.WithResponse(200,
40+
openapitest.WithContent("application/json",
41+
openapitest.WithSchema(schematest.New("string")),
4442
),
4543
),
4644
),
47-
),
4845
),
4946
),
5047
),
@@ -94,20 +91,15 @@ func TestHandler_Schema_Example_Query(t *testing.T) {
9491
app: runtimetest.NewHttpApp(openapitest.NewConfig("3.1.0",
9592
openapitest.WithInfo("foo", "", ""),
9693
openapitest.WithPath("/foo",
97-
openapitest.NewPath(openapitest.WithOperation("GET",
98-
openapitest.NewOperation(
99-
openapitest.WithResponse(200,
100-
openapitest.WithContent("application/json", openapitest.NewContent(
101-
openapitest.WithSchema(schematest.New("string")),
102-
)),
103-
),
104-
openapitest.WithResponse(400,
105-
openapitest.WithContent("application/json", openapitest.NewContent(
106-
openapitest.WithSchema(schematest.New("string")),
107-
)),
94+
openapitest.WithOperation("GET",
95+
openapitest.WithResponse(200,
96+
openapitest.WithContent("application/json",
97+
openapitest.WithSchema(schematest.New("string")),
10898
),
10999
),
110-
),
100+
openapitest.WithResponse(400,
101+
openapitest.WithContent("application/json", openapitest.WithSchema(schematest.New("string"))),
102+
),
111103
),
112104
),
113105
),

providers/openapi/components.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,6 @@ type Components struct {
1919

2020
type ComponentParameters map[string]*ParameterRef
2121

22-
func (c *Components) parse(config *dynamic.Config, reader dynamic.Reader) error {
23-
if c.Schemas != nil {
24-
for it := c.Schemas.Iter(); it.Next(); {
25-
if err := it.Value().Parse(config, reader); err != nil {
26-
return fmt.Errorf("parse components failed: parse schema '%s' failed: %w", it.Key(), err)
27-
}
28-
}
29-
}
30-
31-
if err := c.Responses.parse(config, reader); err != nil {
32-
return fmt.Errorf("parse components failed: %w", err)
33-
}
34-
if err := c.RequestBodies.parse(config, reader); err != nil {
35-
return fmt.Errorf("parse components failed: %w", err)
36-
}
37-
if err := c.Parameters.parse(config, reader); err != nil {
38-
return fmt.Errorf("parse components failed: %w", err)
39-
}
40-
if err := c.Examples.parse(config, reader); err != nil {
41-
return fmt.Errorf("parse components failed: %w", err)
42-
}
43-
if err := c.Headers.parse(config, reader); err != nil {
44-
return fmt.Errorf("parse components failed: %w", err)
45-
}
46-
if err := c.PathItems.parse(config, reader); err != nil {
47-
return fmt.Errorf("parse components failed: %w", err)
48-
}
49-
50-
return nil
51-
}
52-
5322
func (p ComponentParameters) parse(config *dynamic.Config, reader dynamic.Reader) error {
5423
for name, param := range p {
5524
if err := param.Parse(config, reader); err != nil {

0 commit comments

Comments
 (0)