Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K6] Enhancement: Make operationId accessible inside requests #14787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public k6Check(Integer status, String description) {
}

static class HTTPRequest {
String operationId;
String method;
boolean isDelete;
String path;
Expand All @@ -304,12 +305,13 @@ static class HTTPRequest {
@Nullable
DataExtractSubstituteParameter dataExtract;

public HTTPRequest(String method, String path, @Nullable List<Parameter> query, @Nullable HTTPBody body,
public HTTPRequest(String operationId, String method, String path, @Nullable List<Parameter> query, @Nullable HTTPBody body,
boolean hasBodyExample, @Nullable HTTPParameters params, @Nullable List<k6Check> k6Checks,
DataExtractSubstituteParameter dataExtract) {
// NOTE: https://k6.io/docs/javascript-api/k6-http/del-url-body-params
this.method = method.equals("delete") ? "del" : method;
this.isDelete = method.equals("delete");
this.operationId = operationId;
this.path = path;
this.query = query;
this.body = body;
Expand Down Expand Up @@ -645,7 +647,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
// calculate order for this current request
Integer requestOrder = calculateRequestOrder(operationGroupingOrder, requests.size());

requests.put(requestOrder, new HTTPRequest(method.toString().toLowerCase(Locale.ROOT), path,
requests.put(requestOrder, new HTTPRequest(operationId, method.toString().toLowerCase(Locale.ROOT), path,
queryParams.size() > 0 ? queryParams : null,
bodyOrFormParams.size() > 0 ? new HTTPBody(bodyOrFormParams) : null, hasRequestBodyExample,
params.headers.size() > 0 ? params : null, k6Checks.size() > 0 ? k6Checks : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function() {
{{/variables}}
{{#requests}}

// Request No. {{-index}}
// Request No. {{-index}}: {{{operationId}}}
{
let url = BASE_URL + `{{{path}}}{{=<% %>=}}<%#query%><%#-first%>?<%/-first%><%& key%>=<%& value%><%^-last%>&<%/-last%><%/query%><%={{ }}=%>`;
{{#body}}
Expand Down
74 changes: 37 additions & 37 deletions samples/client/petstore/k6/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function() {
let enumQueryDouble = 'TODO_EDIT_THE_ENUM_QUERY_DOUBLE'; // specify value as there is no example value for this parameter in OpenAPI spec
let enumQueryModelArray = 'TODO_EDIT_THE_ENUM_QUERY_MODEL_ARRAY'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: testEnumParameters
{
let url = BASE_URL + `/fake?enum_query_string_array=${enum_query_string_array}&enum_query_string=${enum_query_string}&enum_query_integer=${enum_query_integer}&enum_query_double=${enum_query_double}&enum_query_model_array=${enum_query_model_array}`;
// TODO: edit the parameters of the request body.
Expand All @@ -46,7 +46,7 @@ export default function() {
sleep(SLEEP_DURATION);
}

// Request No. 2
// Request No. 2: testClientModel
{
let url = BASE_URL + `/fake`;
// TODO: edit the parameters of the request body.
Expand All @@ -62,7 +62,7 @@ export default function() {

group("/fake/outer/boolean", () => {

// Request No. 1
// Request No. 1: fakeOuterBooleanSerialize
{
let url = BASE_URL + `/fake/outer/boolean`;
let params = {headers: {"Content-Type": "application/json", "Accept": "*/*"}};
Expand All @@ -76,7 +76,7 @@ export default function() {

group("/another-fake/dummy", () => {

// Request No. 1
// Request No. 1: 123_test_@#$%_special_tags
{
let url = BASE_URL + `/another-fake/dummy`;
// TODO: edit the parameters of the request body.
Expand All @@ -92,7 +92,7 @@ export default function() {

group("/pet", () => {

// Request No. 1
// Request No. 1: updatePet
{
let url = BASE_URL + `/pet`;
// TODO: edit the parameters of the request body.
Expand All @@ -107,7 +107,7 @@ export default function() {
sleep(SLEEP_DURATION);
}

// Request No. 2
// Request No. 2: addPet
{
let url = BASE_URL + `/pet`;
// TODO: edit the parameters of the request body.
Expand All @@ -124,7 +124,7 @@ export default function() {
group("/user/{username}", () => {
let username = 'TODO_EDIT_THE_USERNAME'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: getUserByName
{
let url = BASE_URL + `/user/${username}`;
let request = http.get(url);
Expand All @@ -136,7 +136,7 @@ export default function() {
sleep(SLEEP_DURATION);
}

// Request No. 2
// Request No. 2: deleteUser
{
let url = BASE_URL + `/user/${username}`;
let request = http.del(url);
Expand All @@ -146,7 +146,7 @@ export default function() {

group("/fake/body-with-binary", () => {

// Request No. 1
// Request No. 1: testBodyWithBinary
{
let url = BASE_URL + `/fake/body-with-binary`;
let params = {headers: {"Content-Type": "image/png", "Accept": "application/json"}};
Expand All @@ -160,7 +160,7 @@ export default function() {

group("/fake_classname_test", () => {

// Request No. 1
// Request No. 1: testClassname
{
let url = BASE_URL + `/fake_classname_test`;
// TODO: edit the parameters of the request body.
Expand All @@ -176,7 +176,7 @@ export default function() {

group("/user/createWithList", () => {

// Request No. 1
// Request No. 1: createUsersWithListInput
{
let url = BASE_URL + `/user/createWithList`;
let params = {headers: {"Content-Type": "application/json", "Accept": "application/json"}};
Expand All @@ -190,7 +190,7 @@ export default function() {

group("/fake/inline-additionalProperties", () => {

// Request No. 1
// Request No. 1: testInlineAdditionalProperties
{
let url = BASE_URL + `/fake/inline-additionalProperties`;
let params = {headers: {"Content-Type": "application/json", "Accept": "application/json"}};
Expand All @@ -204,7 +204,7 @@ export default function() {

group("/store/inventory", () => {

// Request No. 1
// Request No. 1: getInventory
{
let url = BASE_URL + `/store/inventory`;
let request = http.get(url);
Expand All @@ -219,7 +219,7 @@ export default function() {
let password = 'TODO_EDIT_THE_PASSWORD'; // specify value as there is no example value for this parameter in OpenAPI spec
let username = 'TODO_EDIT_THE_USERNAME'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: loginUser
{
let url = BASE_URL + `/user/login?username=${username}&password=${password}`;
let request = http.get(url);
Expand All @@ -232,7 +232,7 @@ export default function() {

group("/fake/outer/composite", () => {

// Request No. 1
// Request No. 1: fakeOuterCompositeSerialize
{
let url = BASE_URL + `/fake/outer/composite`;
// TODO: edit the parameters of the request body.
Expand All @@ -248,7 +248,7 @@ export default function() {

group("/fake/jsonFormData", () => {

// Request No. 1
// Request No. 1: testJsonFormData
{
let url = BASE_URL + `/fake/jsonFormData`;
// TODO: edit the parameters of the request body.
Expand All @@ -265,7 +265,7 @@ export default function() {
group("/fake/{petId}/uploadImageWithRequiredFile", () => {
let petId = 'TODO_EDIT_THE_PETID'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: uploadFileWithRequiredFile
{
let url = BASE_URL + `/fake/${petId}/uploadImageWithRequiredFile`;
// TODO: edit the parameters of the request body.
Expand All @@ -282,7 +282,7 @@ export default function() {
group("/pet/{petId}", () => {
let petId = 'TODO_EDIT_THE_PETID'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: getPetById
{
let url = BASE_URL + `/pet/${petId}`;
let request = http.get(url);
Expand All @@ -294,7 +294,7 @@ export default function() {
sleep(SLEEP_DURATION);
}

// Request No. 2
// Request No. 2: deletePet
{
let url = BASE_URL + `/pet/${petId}`;
let params = {headers: {"api_key": `${apiKey}`, "Accept": "application/json"}};
Expand All @@ -309,7 +309,7 @@ export default function() {

group("/foo", () => {

// Request No. 1
// Request No. 1:
{
let url = BASE_URL + `/foo`;
let request = http.get(url);
Expand All @@ -322,7 +322,7 @@ export default function() {

group("/fake/outer/string", () => {

// Request No. 1
// Request No. 1: fakeOuterStringSerialize
{
let url = BASE_URL + `/fake/outer/string`;
let params = {headers: {"Content-Type": "application/json", "Accept": "*/*"}};
Expand All @@ -343,7 +343,7 @@ export default function() {
let language = 'TODO_EDIT_THE_LANGUAGE'; // specify value as there is no example value for this parameter in OpenAPI spec
let url = 'TODO_EDIT_THE_URL'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: testQueryParameterCollectionFormat
{
let url = BASE_URL + `/fake/test-query-parameters?pipe=${pipe}&ioutil=${ioutil}&http=${http}&url=${url}&context=${context}&language=${language}&allowEmpty=${allowEmpty}`;
let request = http.put(url);
Expand All @@ -357,7 +357,7 @@ export default function() {
group("/store/order/{order_id}", () => {
let orderId = 'TODO_EDIT_THE_ORDER_ID'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: getOrderById
{
let url = BASE_URL + `/store/order/${order_id}`;
let request = http.get(url);
Expand All @@ -369,7 +369,7 @@ export default function() {
sleep(SLEEP_DURATION);
}

// Request No. 2
// Request No. 2: deleteOrder
{
let url = BASE_URL + `/store/order/${order_id}`;
let request = http.del(url);
Expand All @@ -380,7 +380,7 @@ export default function() {
group("/pet/findByStatus", () => {
let status = 'TODO_EDIT_THE_STATUS'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: findPetsByStatus
{
let url = BASE_URL + `/pet/findByStatus?status=${status}`;
let request = http.get(url);
Expand All @@ -394,7 +394,7 @@ export default function() {
group("/fake/body-with-query-params", () => {
let query = 'TODO_EDIT_THE_QUERY'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: testBodyWithQueryParams
{
let url = BASE_URL + `/fake/body-with-query-params?query=${query}`;
// TODO: edit the parameters of the request body.
Expand All @@ -411,7 +411,7 @@ export default function() {
group("/pet/{petId}/uploadImage", () => {
let petId = 'TODO_EDIT_THE_PETID'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: uploadFile
{
let url = BASE_URL + `/pet/${petId}/uploadImage`;
// TODO: edit the parameters of the request body.
Expand All @@ -428,7 +428,7 @@ export default function() {
group("/fake/http-signature-test", () => {
let query1 = 'TODO_EDIT_THE_QUERY_1'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: fake-http-signature-test
{
let url = BASE_URL + `/fake/http-signature-test?query_1=${query_1}`;
// TODO: edit the parameters of the request body.
Expand All @@ -444,7 +444,7 @@ export default function() {

group("/user", () => {

// Request No. 1
// Request No. 1: createUser
{
let url = BASE_URL + `/user`;
// TODO: edit the parameters of the request body.
Expand All @@ -460,7 +460,7 @@ export default function() {

group("/fake/property/enum-int", () => {

// Request No. 1
// Request No. 1: fakePropertyEnumIntegerSerialize
{
let url = BASE_URL + `/fake/property/enum-int`;
// TODO: edit the parameters of the request body.
Expand All @@ -476,7 +476,7 @@ export default function() {

group("/user/createWithArray", () => {

// Request No. 1
// Request No. 1: createUsersWithArrayInput
{
let url = BASE_URL + `/user/createWithArray`;
let params = {headers: {"Content-Type": "application/json", "Accept": "application/json"}};
Expand All @@ -490,7 +490,7 @@ export default function() {

group("/fake/body-with-file-schema", () => {

// Request No. 1
// Request No. 1: testBodyWithFileSchema
{
let url = BASE_URL + `/fake/body-with-file-schema`;
// TODO: edit the parameters of the request body.
Expand All @@ -507,7 +507,7 @@ export default function() {
group("/pet/findByTags", () => {
let tags = 'TODO_EDIT_THE_TAGS'; // specify value as there is no example value for this parameter in OpenAPI spec

// Request No. 1
// Request No. 1: findPetsByTags
{
let url = BASE_URL + `/pet/findByTags?tags=${tags}`;
let request = http.get(url);
Expand All @@ -520,7 +520,7 @@ export default function() {

group("/store/order", () => {

// Request No. 1
// Request No. 1: placeOrder
{
let url = BASE_URL + `/store/order`;
// TODO: edit the parameters of the request body.
Expand All @@ -536,7 +536,7 @@ export default function() {

group("/user/logout", () => {

// Request No. 1
// Request No. 1: logoutUser
{
let url = BASE_URL + `/user/logout`;
let request = http.get(url);
Expand All @@ -549,7 +549,7 @@ export default function() {

group("/fake/health", () => {

// Request No. 1
// Request No. 1:
{
let url = BASE_URL + `/fake/health`;
let request = http.get(url);
Expand All @@ -562,7 +562,7 @@ export default function() {

group("/fake/outer/number", () => {

// Request No. 1
// Request No. 1: fakeOuterNumberSerialize
{
let url = BASE_URL + `/fake/outer/number`;
let params = {headers: {"Content-Type": "application/json", "Accept": "*/*"}};
Expand Down