Open thim81 opened 3 years ago
Hey @thim81,
thanks for filing the issue. I'd be happy to see any contribution from you or any member of the community. Currently I am busy doing other things and this is not one of the priorities, but I might look at it in the future. Also, I can help with the code review if you create a PR.
Hi @mostafa,
Fully understood. Do you find it a valuable addition?
Since I'm not at home of the code base, can you perhaps me towards the piece in the code where you would want to see this extension being implemented?
@thim81 Of course!
This is the file that generates the k6 script. And this is the template I used to generate the script. In this case, all those TODO_EDIT_THE_{{{value}}}
should be replaced by correct examples. In the code, look for instances of the Parameter
static class. Let me know if you need more information!
Hey @thim81,
have you been able to add the feature/enhancement? Do you need any help?
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.
Is your feature request related to a problem? Please describe.
The K6 generator, generates an almost ready to use K6 script.
Example
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:
Describe the solution you'd like
In the OpenApi you can define "example" values
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.