diff --git a/pkg/runner/http.go b/pkg/runner/http.go index 548d422..5f74d0e 100644 --- a/pkg/runner/http.go +++ b/pkg/runner/http.go @@ -247,11 +247,14 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st }, } - for _, param := range swagger.Parameters { - switch param.In { - case "query": - // TODO should have a better way to provide the initial value - testcase.Request.Query[param.Name] = "todo" + switch testcase.Request.Method { + case http.MethodGet: + for _, param := range swagger.Paths.Paths[api].Get.Parameters { + switch param.In { + case "query": + // TODO should have a better way to provide the initial value + (&(testcase.Request)).Query[param.Name] = "todo" + } } } result = append(result, testcase) diff --git a/pkg/runner/http_test.go b/pkg/runner/http_test.go index c600201..c64eecd 100644 --- a/pkg/runner/http_test.go +++ b/pkg/runner/http_test.go @@ -1,5 +1,5 @@ /* -Copyright 2023 API Testing Authors. +Copyright 2023-2024 API Testing Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -539,6 +539,7 @@ func TestBodyFiledsVerify(t *testing.T) { func TestGetSuggestedAPIs(t *testing.T) { runner := NewSimpleTestCaseRunner() + runner.WithSuite(nil) // not a swagger result, err := runner.GetSuggestedAPIs(&atest.TestSuite{}, "") assert.NoError(t, err, err) @@ -557,6 +558,7 @@ func TestGetSuggestedAPIs(t *testing.T) { assert.NotEmpty(t, result) method := result[0].Request.Method assert.Equal(t, strings.ToUpper(method), method) + assert.Equal(t, "todo", result[0].Request.Query["text"]) } func TestIsStructContent(t *testing.T) { diff --git a/pkg/runner/testdata/swagger.json b/pkg/runner/testdata/swagger.json index af40d4c..34afdd3 100644 --- a/pkg/runner/testdata/swagger.json +++ b/pkg/runner/testdata/swagger.json @@ -32,7 +32,16 @@ }, "post": { "summary": "summary", - "operationId": "createUser" + "operationId": "createUser", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + } } }, "/api/v1/users/{user}": { @@ -49,5 +58,23 @@ "operationId": "updateUser" } } + }, + "components": { + "schemas": { + "User": { + "title": "User", + "type": "object", + "properties": { + "username": { + "type": "string", + "description": "username" + }, + "age": { + "type": "integer", + "format": "int32" + } + } + } + } } }