Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[k6] OpenAPI code generator for k6 API load-testing tool (ES5.1+) #5300

Merged
merged 3 commits into from Feb 19, 2020

Conversation

@mostafa
Copy link
Contributor

mostafa commented Feb 12, 2020

k6 is an API load-testing tool created by Load Impact AB to help developers and DevOps people test the performance of their APIs. It is written in Go, and is scriptable in JavaScript, supporting ES5.1+. At Load Impact, we have converters/codegens for HAR files, Postman collections and JMeter to help users of k6 easily be onboard to our tool.

Since we focus on API load-testing, we thought it would be a good idea to create a Swagger/OpenAPI code generator, too. So, after much research, we found that this project is the officially developed and maintained one that we can reliably put our efforts on. Thus we created this code generator, to help generate k6 scripts from Swagger 2.0 specification documents.

This is our first PoC and we definitely would like to hear your feedback to improve it further. There are some questions for the official maintainers:

  1. Should we also edit the README.md and add ourselves as Template Creators and Technical Committee for k6?
  2. Does our implementation seem like a good starting point for further improving the project?

We really appreciate your feedback on this.
Note: On @wing328's suggestion I have ported the code from swagger-api/swagger-codegen#10013 to this project.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
@mostafa mostafa requested a review from wing328 Feb 12, 2020
@wing328 wing328 closed this Feb 17, 2020
@wing328 wing328 reopened this Feb 17, 2020
@wing328

This comment has been minimized.

Copy link
Member

wing328 commented Feb 17, 2020

@mostafa Thanks for the PR. I notice some build errors. I'll try to update your branch directly to fix those issues.

@wing328

This comment has been minimized.

Copy link
Member

wing328 commented Feb 17, 2020

I don't have right to push to your branch. Please apply the following fix when you've time:

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/k6Codegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/k6Codegen.java
index 72d9ac2edc..a220b67d32 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/k6Codegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/k6Codegen.java
@@ -334,7 +334,7 @@ public class k6Codegen extends DefaultCodegen implements CodegenConfig {
                                     "http.file(open(\"/path/to/file.bin\", \"b\"), \"test.bin\")");
                         } else {
                             k6Parameter = new Parameter(parameter.paramName, !reference.isEmpty() ? reference
-                                    : getDoubleQuotedString(parameter.dataType.toLowerCase()));
+                                    : getDoubleQuotedString(parameter.dataType.toLowerCase(Locale.ROOT)));
                         }
 
                         bodyOrFormParams.add(k6Parameter);
@@ -349,13 +349,13 @@ public class k6Codegen extends DefaultCodegen implements CodegenConfig {
                         switch (parameter.getIn()) {
                             case "header":
                                 httpParams.add(new Parameter(parameter.getName(), getTemplateString(parameter.getName())));
-                                extraParameters.add(new Parameter(parameter.getName(), parameter.getName().toUpperCase()));
+                                extraParameters.add(new Parameter(parameter.getName(), parameter.getName().toUpperCase(Locale.ROOT)));
                                 break;
                             case "path":
                             case "query":
                                 if (parameter.getIn().equals("query"))
                                     queryParams.add(new Parameter(parameter.getName(), getVariable(parameter.getName())));
-                                variables.add(new Parameter(parameter.getName(), parameter.getName().toUpperCase()));
+                                variables.add(new Parameter(parameter.getName(), parameter.getName().toUpperCase(Locale.ROOT)));
                                 break;
                             default:
                                 break;
@@ -407,7 +407,7 @@ public class k6Codegen extends DefaultCodegen implements CodegenConfig {
         StringBuilder reference = new StringBuilder();
         int modelEntrySetSize = model.getAllVars().size();
         for (CodegenProperty property : model.getAllVars()) {
-            reference.append(getDoubleQuotedString(property.name)).append(": ").append(getDoubleQuotedString(property.dataType.toLowerCase()));
+            reference.append(getDoubleQuotedString(property.name)).append(": ").append(getDoubleQuotedString(property.dataType.toLowerCase(Locale.ROOT)));
             if (modelEntrySetSize > 1)
                 reference.append(", ");
         }
@@ -430,7 +430,7 @@ public class k6Codegen extends DefaultCodegen implements CodegenConfig {
 
     /**
      * Concatenates an array of path segments into a path string.
-     * 
+     *
      * @param segments The path segments to concatenate. A segment may contain
      *                 either of the file separator characters '\' or '/'. A segment
      *                 is ignored if it is <code>null</code>, empty or
@wing328 wing328 added this to the 4.3.0 milestone Feb 17, 2020
@wing328

This comment has been minimized.

Copy link
Member

wing328 commented Feb 17, 2020

Should we also edit the README.md and add ourselves as Template Creators and Technical Committee for k6?

I'll do that in a separate PR.

Does our implementation seem like a good starting point for further improving the project?

I think so. I'll consider it as a beta release so as to gather feedback from the community.

@wing328 wing328 added the Client: k6 label Feb 17, 2020
@wing328

This comment has been minimized.

Copy link
Member

wing328 commented Feb 18, 2020

The CircleCI failed due to outdated documentation. I'll push a fix (commit) after merging this PR.

I'll also file a PR with various improvements to this new generator.

@wing328 wing328 merged commit 79caba8 into OpenAPITools:master Feb 19, 2020
5 of 6 checks passed
5 of 6 checks passed
ci/circleci Your tests failed on CircleCI
Details
Shippable Run 14822 status is SUCCESS.
Details
ci/bitrise/4a2b10a819d12b67/pr Passed - openapi-generator
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/drone/pr Build is passing
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
MikailBag added a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
…enAPITools#5300)

* Add generator for converting OpenAPI spec to k6 script

* Fixed names and URL

* Add @wing328's proposed changes to fix the builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.