Skip to content

Commit 70a8685

Browse files
authored
feat: provide the query parameter via swagger (#339)
Co-authored-by: rick <[email protected]>
1 parent a8822e7 commit 70a8685

File tree

7 files changed

+118
-9
lines changed

7 files changed

+118
-9
lines changed

Diff for: .gitpod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
tasks:
33
- init: make init-env install-precheck
4-
before: IMG_TOOL=docker GOPROXY= make build-ext copy-ext build-image
4+
before: IMG_TOOL=docker GOPROXY= make build-image
55
command: cd console/atest-ui/ && npm i
66

77
ports:

Diff for: pkg/apispec/fake.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package apispec
218

319
type fakeAPISpec struct {

Diff for: pkg/apispec/fake_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package apispec_test
218

319
import (

Diff for: pkg/apispec/swagger.go

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package apispec
218

319
import (
@@ -9,14 +25,30 @@ import (
925
)
1026

1127
type Swagger struct {
12-
Swagger string `json:"swagger"`
13-
Paths map[string]map[string]SwaggerAPI `json:"paths"`
14-
Info SwaggerInfo `json:"info"`
28+
Swagger string `json:"swagger"`
29+
// Paths includes all the API requests.
30+
// The keys is the HTTP request method which as lower-case, for example: get, post.
31+
Paths map[string]map[string]SwaggerAPI `json:"paths"`
32+
Info SwaggerInfo `json:"info"`
1533
}
1634

1735
type SwaggerAPI struct {
18-
OperationId string `json:"operationId"`
19-
Summary string `json:"summary"`
36+
OperationId string `json:"operationId"`
37+
Parameters []Parameter `json:"parameters"`
38+
Summary string `json:"summary"`
39+
}
40+
41+
type Parameter struct {
42+
Name string `json:"name"`
43+
// In represents the parameter type, supported values: query, path
44+
In string `json:"in"`
45+
Required bool `json:"required"`
46+
Schema Schema `json:"schema"`
47+
}
48+
49+
type Schema struct {
50+
Type string `json:"type"`
51+
Format string `json:"format"`
2052
}
2153

2254
type SwaggerInfo struct {

Diff for: pkg/apispec/swagger_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package apispec_test
218

319
import (

Diff for: pkg/runner/http.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,23 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st
228228
result = []*testing.TestCase{}
229229
for api, item := range swaggerAPI.Paths {
230230
for method, oper := range item {
231-
result = append(result, &testing.TestCase{
231+
testcase := &testing.TestCase{
232232
Name: oper.OperationId,
233233
Request: testing.Request{
234234
API: api,
235235
Method: strings.ToUpper(method),
236+
Query: make(testing.SortedKeysStringMap),
236237
},
237-
})
238+
}
239+
240+
for _, param := range oper.Parameters {
241+
switch param.In {
242+
case "query":
243+
// TODO should have a better way to provide the initial value
244+
testcase.Request.Query[param.Name] = "todo"
245+
}
246+
}
247+
result = append(result, testcase)
238248
}
239249
}
240250
}

Diff for: pkg/runner/testdata/swagger.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@
99
"/api/v1/users": {
1010
"get": {
1111
"summary": "summary",
12-
"operationId": "getUsers"
12+
"operationId": "getUsers",
13+
"parameters": [
14+
{
15+
"name": "text",
16+
"in": "query",
17+
"required": true,
18+
"schema": {
19+
"type": "string"
20+
}
21+
},
22+
{
23+
"name": "count",
24+
"in": "path",
25+
"required": true,
26+
"schema": {
27+
"type": "integer",
28+
"format": "int32"
29+
}
30+
}
31+
]
1332
},
1433
"post": {
1534
"summary": "summary",

0 commit comments

Comments
 (0)