[REQ] K6 generator - Use openapi examples values as query parameters & body values
See original GitHub issueIs your feature request related to a problem? Please describe.
The K6 generator, generates an almost ready to use K6 script.
Example
group("/portal/v1/domainclusters/{domainClusterId}", () => {
let domainClusterId = "TODO_EDIT_THE_DOMAINCLUSTERID";
let url = BASE_URL + `/portal/v1/domainclusters/${domainClusterId}`;
// Request No. 1
let request = http.get(url);
check(request, {
"Success": (r) => r.status === 200
});
sleep(SLEEP_DURATION);
// Request No. 2
// TODO: edit the parameters of the request body.
body = {"name": "string", "servers": "list"};
params = {headers: {"Content-Type": "application/json"}};
request = http.put(url, body, params);
check(request, {
"Success": (r) => r.status === 204
});
sleep(SLEEP_DURATION);
In the above there are 2 parts of the generated script, that require some manual modifications.
Query parameter:
let domainClusterId = "TODO_EDIT_THE_DOMAINCLUSTERID";
Request Body
body = {"name": "string", "servers": "list"};
The goal is to use the generated script in an Continuous integration flow.
The flow would be:
- Manage OpenApi spec
- Push to OA to GIT
- Trigger build pipeline – generated documentation – generate postman collection – generate a K6 script via the openapi-generator – trigger a load test via K6
Describe the solution you’d like
In the OpenApi you can define “example” values
'/portal/v1/domainclusters/{domainClusterId}':
get:
operationId: get-domain-clusters-id
tags:
- DomainClusters
summary: Get a specific domain cluster configuration
parameters:
- domainClusterId:
name: domainClusterId
description: ID of the domain cluster setting.
in: path
required: true
schema:
type: string
nullable: true
example: f0c01c3a-6880-46c3-abb3-7a45828d1c45
responses:
'200':
description: Success
put:
operationId: put-domain-clusters-id
tags:
- DomainClusters
summary: Update a domain cluster configuration
parameters:
- domainClusterId:
name: domainClusterId
description: ID of the domain cluster setting.
in: path
required: true
schema:
type: string
nullable: true
example: f0c01c3a-6880-46c3-abb3-7a45828d1c45
requestBody:
description: The updated values
content:
application/json:
schema:
required:
- name
type: object
properties:
name:
description: The name of the domain cluster.
type: string
example: CLUSTER-1
servers:
description: The list of servers.
type: array
items:
type: string
example:
- s1
- s2
responses:
'204':
description: Success
A handy solution would be to use the examples, like os
Query parameter:
let domainClusterId = "TODO_EDIT_THE_DOMAINCLUSTERID";
Take the example values from OpenApi params > servers > schema > example: f0c01c3a-6880-46c3-abb3-7a45828d1c45
which would result in:
let domainClusterId = "f0c01c3a-6880-46c3-abb3-7a45828d1c45";
Request Body
body = {"name": "string", "servers": "list"};
Take the example values from OpenApi requestBody > content > properties > name > example: CLUSTER-1 requestBody > content > properties > servers > example: - S1 - S2
Describe alternatives you’ve considered
creating a PR, but I’m not sure how to get started with the excellent K6 generator from @mostafa , due to no experience in JAVA development and if the mentioned example data is available in the OpenApi class.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Hi,
As part of recent automation work done on a commercial project, where I utilized the K6 OpenAPI generator, I hit this issue where examples defined for path/query parameters were not taken into account. Therefore, the script produced was not really usable, only a skeleton. I needed to generate script which was fully ready to run, out-of-the box, so smoke tests (https://k6.io/docs/test-types/smoke-testing/) could be run as part of CI/CD pipeline.
I went ahead and added what was needed, and now, Data In Motion (https://www.datainmotion.de/), client for whom this work was done, generously agreed to share this with the community.
So that’s the background on the PR which I just opened: https://github.com/OpenAPITools/openapi-generator/pull/9750
This addresses extracting examples defined for path/query parameters; as you know, there are also examples defined at
requestBody
level and other (https://swagger.io/docs/specification/adding-examples/); hopefully the community can pick it up from there and enhance further – path/query params was all that was needed for this particular use case.Hi,
More goodies: https://github.com/OpenAPITools/openapi-generator/pull/10614
With this latest MR, this feature request (i.e. #8378) is now feature complete.
Please see https://github.com/OpenAPITools/openapi-generator/pull/10614 for more info.
New code is documented. Entire solution will be showcased as part of the upcoming EclipseCon 2021 session: “Automated testing of OpenAPI-described RESTful microservices utilizing open source tools” https://www.eclipsecon.org/2021/sessions/automated-testing-openapi-described-restful-microservices-utilizing-open-source-tools
Hopefully formatting is now OK, in case of any problems please let me know.