OpenAPI to K6 Converter Features

Hey K6 Team,

I am working in a demo with K6 and OpenApi to present in the company. The idea is to use the spec file from OpenApi in order to build the performance test.

I have been able to go through the documentation and the brilliant post that you have here: Load Testing Your API with Swagger/OpenAPI and k6

Correct me if I am wrong but I see the following behavior

  • Endpoints defined in Swagger are transformed into a group(K6)
  • Endpoints with different HTTP Methods defined will be transformed inside 1 group adding a comment like //Request No.1, Request No 2, etc
  • Responses defined in swagger file are transformed into a check(K6)

If there is something else that can be used in the conversation, I would be glad if you could share this with me.

I am concerned about those scenarios that you need to run Request 1 from Endpoint 1, Request 3 from Endpoint 2, and Request 4 from Endpoint 3. Is there an easy way to do this? or the converted will just convert this spec file into the structure mentioned above?

I would like to know if you will keep extending this with to help the teams to use this converted to start writing scenarios with them in an easy way or how can I contribute with the project. Right now some cool stuff that could be added are :

  • Set the Parameters defined in swagger file as Environment variables. On this way it will not be needed to update the “TODO_EDIT”
  • Possible to automatic replace the “TODO_EDIT” with a value, for example reading and replacing this before executing the test with K6
  • Use parameters definition like required and minLenght to make the conversion of the spec file into a k6 script

Thank you very much for your time
Hope you have a nice week
LH

Hi @LucasHartridge,

welcome to the forums and thanks for the feedback.

Regarding your observations:

  1. Yes, endpoints belonging to a path are transforms into groups in k6.
  2. Yes, same as 1, because they belong to the same path.
  3. Either default output (usually 2XX series) or, if present, 200 is checked, ref: responses as checks.
  4. These are the schemas I’ve defined, which get transformed into a mustache template, which you then see the transformed output in.
  5. The structure is fixed and any change to the order of requests should be handled manually, since it can’t be inferred from the specification file, AFAIK.
  6. If you want to contribute in any way, I suggest you to have a look at the PRs William and I have made to the open-api generator project. There you’ll see how I managed to write an extension and how we managed to merge it. This is the main PR. Go through the code and templates and docs, and together we’ll try to make things work.

Regarding your suggestions/changes:

  1. That would be a nice addition. But I postponed it for the initial release, so that I can get more feedback. I’d be happy to see such a contribution. For the environment variables, only the template and the corresponding "TODO_EDIT_..." should be changed in the extension.
  2. Please have a look at the javascript extension in the generator. You can also add command-line options that can automate this replace.
  3. I am not sure how that’ll work, but if you have an idea, I’d be happy to hear and help you contribute.

Thanks,
M. Moradian.

Hey @mostafa

Thank you very much for your fast anwser, all the details help me to clarify how this is working at the moment

This allows me to understand what I can do to extend the current work in order to set up an easy process to get test working without “human” interaction

I will start working on this and if I figure out some process that it could help the community I will share it with you and William

Thanks,
LH

1 Like