Created by: ideas-into-software
Following up on the "parameter example data extraction" enhancement merged via https://github.com/OpenAPITools/openapi-generator/pull/9750, this MR brings additional significant improvements to the K6 OpenAPI generator, i.e.:
- request body example data extraction
- request grouping and ordering
- response visibility
- request data extraction for chaining requests
Most of these are accomplished via custom OpenAPI extensions (https://swagger.io/docs/specification/openapi-extensions/) introduced, i.e.:
-
x-k6-openapi-operation-grouping
– operation grouping - group operations and define their ordering; useful e.g. for automatically generated scenario tests -
x-k6-openapi-operation-response
– operation response - for now, allows to hide given operation response, so that in case of multiple 2xx responses, generated script checks only against e.g. code 200 responses -
x-k6-openapi-operation-dataextract
– extract data from operation - allows to specify path to value in body of response which should be extracted and assigned to variable for later use by other operations; useful e.g. for automatically generated load test scripts
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
In a nutshell, with these additional enhancements, it possible not only to specify all of the example data and use it in the ready-to-run generated script, but to also generate ready-to-run scenario tests as well as load tests.
This allows for integrating the entire solution into CI/CD pipeline, i.e. as an additional, post-automated-deployment step, running automated REST API testing via automatically generated smoke tests / load tests / scenario tests, generated off on latest OpenAPI spec.
Obviously, generating OpenAPI spec itself is out of the scope for this project – but can be easily integrated into pipeline via existing gradle/maven plugins (e.g. io.swagger.core.v3.swagger-gradle-plugin
) and run in a separate, earlier, step of the pipeline. Also, for automated REST API testing as part of CI/CD pipeline, continuous deployment must be in place – i.e. latest version of application exposing such REST API must be first deployed.
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(5.3.0),6.0.x
-
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.