[K6 Generator] various enhancements (request body example data extraction, support for generating scenario tests and load tests out of the box, and much more)#11106
Conversation
* request body example data extraction * request grouping and ordering * response visibility * request data extraction for chaining requests Signed-off-by: Michael H. Siemaszko <[email protected]>
- regenerated samples Signed-off-by: Michael H. Siemaszko <[email protected]>
* resolved merge conflicts * replaced deprecated dependency `org.apache.commons.lang3.StringEscapeUtils` Signed-off-by: Michael H. Siemaszko <[email protected]>
| } | ||
| } | ||
| } catch (NullPointerException e) { | ||
| } catch (NullPointerException ignored) { |
There was a problem hiding this comment.
let's log this exception and learn what's broken
| return params != null && params.size() > 0; | ||
| } | ||
|
|
||
| private static boolean nonempty(Map<?, ?> params) { |
|
|
||
| if (cgOperation.getHasVendorExtensions() | ||
| && cgOperation.vendorExtensions.containsKey(X_OPERATION_DATAEXTRACT) | ||
| && cgOperation.vendorExtensions.get(X_OPERATION_DATAEXTRACT) instanceof java.util.Map) { |
There was a problem hiding this comment.
instanceof java.util.Map, don't we have Map already imported to do intanceof Map?
There was a problem hiding this comment.
That's a boolean check.
| Map<String, DataExtractSubstituteParameter> dataExtractSubstituteParams, HTTPRequestGroup requestGroup) { | ||
|
|
||
| if (!dataExtractSubstituteParams.isEmpty()) { | ||
| List<String> existingVariablesNames = requestGroup.variables.stream().map(v -> v.key) |
There was a problem hiding this comment.
List<String> existingVariablesNames = requestGroup.variables.stream().map(v -> v.key)
.collect(Collectors.toList());
Set<DataExtractSubstituteParameter> initializeVariables = dataExtractSubstituteParams.values().stream()
.filter(p -> !existingVariablesNames.contains(toVarName(p.paramName))).collect(Collectors.toSet());
this filter condition will be O(1) fast if existingVariablesNames is a Set, when existingVariablesNames is a List filter will be O(n)
| Set<DataExtractSubstituteParameter> initializeVariables = dataExtractSubstituteParams.values().stream() | ||
| .filter(p -> !existingVariablesNames.contains(toVarName(p.paramName))).collect(Collectors.toSet()); | ||
|
|
||
| if (!initializeVariables.isEmpty()) { |
There was a problem hiding this comment.
check if (!initializeVariables.isEmpty()) { not required when using for-each loop
| check(request, { | ||
| { | ||
| let url = BASE_URL + `/pet/findByStatus?status=${status}`; | ||
|
|
There was a problem hiding this comment.
still triple empty lines :P
There was a problem hiding this comment.
I think I haven't regenerated the file.
There was a problem hiding this comment.
Interesting, the pipeline passed on 5082527 when the sample project was out of date.
There was a problem hiding this comment.
That was strange to me, too.
|
|
||
|
|
||
| let request = http.del(url); | ||
|
|
|
|
||
| String operationId = operation.getOperationId(); | ||
|
|
||
| boolean hasRequestBodyExample = false; |
There was a problem hiding this comment.
initialisation of this can go to line 558
There was a problem hiding this comment.
An outer block needs this variable if I move it inside the if block.
|
|
||
| final CodegenOperation cgOperation = super.fromOperation(path, method.name(), operation, null); | ||
|
|
||
| String operationId = operation.getOperationId(); |
There was a problem hiding this comment.
this line can go a lot lower than here
|
|
||
| final Operation operation = methodOperation.getValue(); | ||
| final PathItem.HttpMethod method = methodOperation.getKey(); | ||
| OptionalInt operationGroupingOrder = OptionalInt.empty(); |
There was a problem hiding this comment.
had no idea OptionalInt is a thing 👍
| List<Parameter> bodyOrFormParams) { | ||
|
|
||
| Optional<Map.Entry<String, Example>> requestBodyExampleEntry = requestBody.getContent().get(contentTypeValue) | ||
| .getExamples().entrySet().stream().findFirst(); |
There was a problem hiding this comment.
this chain map->set->stream->optional is quite slow, how often is this method call? might be worth to new ArrayList(getExamples().entrySet()).get(0)?
There was a problem hiding this comment.
Only once per request. It doesn't matter much.
| * @return true if parameter exists, false otherwise | ||
| */ | ||
| private static boolean nonempty(List<?> params) { | ||
| private static boolean nonEmpty(List<?> params) { |
There was a problem hiding this comment.
@agilob This is unrelated to our code, but I changed it nevertheless.
| for (Map.Entry<?, ?> respExtensionEntry : respExtensions.entrySet()) { | ||
|
|
||
| if (X_OPERATION_RESPONSE_HIDE.equals(String.valueOf(respExtensionEntry.getKey()))) { | ||
| hideOperationResponse = Boolean.parseBoolean(respExtensionEntry.getValue().toString()); |
There was a problem hiding this comment.
should this have a break statement after setting this to true? effectively, now hideOperationResponse will have the last value of respExtensionEntry.getValue(), and if you want the last value, then we don't need a loop here, and since we're iterating on respExtensions.entrySet() a Set, the last value is not deterministic, so method might produce different value on every run.
|
@agilob Thanks to you for the meticulous review! Finally mergeable? |
|
There is no technical commette for k6, so it now depends on when @wing328 or @jimschubert can merge it |
| inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/k6 | ||
| additionalProperties: | ||
| appName: PetstoreClient |
There was a problem hiding this comment.
There's already one in ./bin/configs/other/k6.yaml.
I'll remove it after merging this PR.
|
Hello, good afternoon, I have detected that in the version change from 5.3.0 to 5.3.1 there is a bug that is dragging to the latest current version v7.7.0. The bug itself is to generate more than 2 methods per path, ie if I have a path "/users" with a "GET, POST, PUT, PATCH" I will only generate 2 of the methods leaving the others. I pass code V5.3.0 group("/users/{userId}", () => { group("/users/{userId}", () => { |
This PR builds on top of the PR #10614 by @ideas-into-software and fixes an issue I found while reviewing the code, and that is the empty lines in the output script.
@agilob @wing328 @ideas-into-software I'd be happy to have your feedback.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(5.3.0),6.0.x