question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ] K6 generator - Use openapi examples values as query parameters & body values

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
ideas-into-softwarecommented, Jun 11, 2021

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.

3reactions
ideas-into-softwarecommented, Oct 17, 2021

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 toolshttps://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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load Testing Your API with Swagger/OpenAPI and k6
Body parameters are in the form of { variable: "datatype" }. Change the datatype to the desired value. Nested body parameters follow the...
Read more >
Data Parameterization - K6
This page gives some examples of how to parameterize data in a test script. Parameterization is typically necessary when Virtual Users (VUs) will ......
Read more >
post( url, [body], [params] ) - Grafana k6
Issue an HTTP POST request. ... connect( url, params, callback ) · Params ... Using an object as body, the headers will automatically...
Read more >
Examples & Tutorials - Grafana k6
The k6 Examples & Tutorials is a directory with common k6 examples and the most popular tutorials using k6.
Read more >
URLs with query parameters - Grafana k6
How to use URL and URLSearchParams imported from jslib.k6.io to construct URLs with/without query parameters. URL. URL. 1import { ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found