OpenAPITools / OpenAPITools/openapi-generator
[REQ] K6 generator - Use openapi examples values as query parameters & body values
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the K6 generator entry point and trace how path parameters and request bodies are assembled from the OpenAPI model. Check how schema and property examples are exposed, then verify generated scripts use those values for path parameters and body fields instead of TODO or placeholder values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100