zerocode icon indicating copy to clipboard operation
zerocode copied to clipboard

Support OpenAPI Specification

Open BeTheCodeWithYou opened this issue 6 years ago • 20 comments

It would be nice if we can support Open API Spec in terms of generating zero code tests directly from api spec.

Add more details what all can be supported in the library in context of open spec.

Open Spec reference https://github.com/OAI/OpenAPI-Specification

Requirement from @warademilind :

--- write here ---

Requirement from @SuyogSSS :

--- write here ---

BeTheCodeWithYou avatar Jan 24 '19 22:01 BeTheCodeWithYou

Nice one.

santhoshTpixler avatar Jan 30 '19 14:01 santhoshTpixler

@BeTheCodeWithYou may I work on this issue?

pgmpofu avatar Mar 02 '19 01:03 pgmpofu

@pgmpofu thanks for interest in contributing. Yes please you could very well pickup this item. Would be great if we can discuss on the approach you are looking to implement.

idea is to develop zerocode plugin/utility and use it in below scenario

AC

GIVEN a REST API contract defined in the Open Spec WHEN zerocdoe utility is executed THEN it generates ZeroCode test JSON steps.

example:- uber.json in Open API Spec ( this is just a sample JSON. you could create a simple json based on open spec and then proceed ) https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/uber.json

@authorjapps add more points to AC if you think of.

BeTheCodeWithYou avatar Mar 02 '19 14:03 BeTheCodeWithYou

Can I work on this issue ?

respondsid avatar Apr 01 '19 22:04 respondsid

Please assign it to me

respondsid avatar Apr 01 '19 22:04 respondsid

@respondsid , Yes will do. Thanks 👍 Can you please fork the repo ? Basically we collaborate this way... (a bit of discipline for all our benefits)

  1. The new contributors fork the Zerocode repo to their own repo and make changes there.

    Just press fork button

  2. Once the impl/fix is done, they raise a PR
  3. Once PR is approved, we add them to the contributors list.
  4. And display their name in our Author/Collaborator page 👍

@pgmpofu, it seems like you are bit occupied in your current work, which is fine. But you can certainly help us in reviewing the PR. We will inform you when the PR is ready.

authorjapps avatar Apr 02 '19 08:04 authorjapps

@respondsid , Basically our approach could be in this way. Once we figure out how to parse the open-api/swagger spec-json, we have to fit the url, method, request, response to the below two classes

org.jsmart.zerocode.core.domain.Step

org.jsmart.zerocode.core.domain.ScenarioSpec

You can use the constructor of the above classes to generate the JSON steps.

Then just

mapper.writeValueAsString(step); //<--- only a step and/or mapper.writeValueAsString(scenarioSpec); //<--- Scenario with steps

Initially we could assume that

  • Open API spec json is available to us somewhere in the src/test/resources or
    • Somewhere in the internet/gitrepo (we can try this in the next version in a separate ticket)
    • A maven Plugin (we will try in next version in separate ticket)
  • Then we will have a util class e.g. OpenSpecApiToZeroCodeStepGenerator.java with method e.g. List<String) generate(String openSpecJsonPath)
    • Each item in the list will be a scenario test-case having one or more steps(depending on the OpenApi spec)
  • This generate method will also write to target/generated-tests
    • The number of items in the List<String> will be generated as zerocode .json test-case file
  • For time being we can name the files as <resourceName_crud_test.json>

authorjapps avatar Apr 03 '19 19:04 authorjapps

Oh thanks for the pointer i was planni g on using mustache temolates but this ine sounda even better

On Wed, Apr 3, 2019, 3:59 PM authorjapps [email protected] wrote:

@respondsid https://github.com/respondsid , Basically our approach could be in this way. Once we figure out how to parse the open-api/swagger spec-json, we have to fit the url, method, request, response to the below two classes

org.jsmart.zerocode.core.domain.Step

org.jsmart.zerocode.core.domain.ScenarioSpec

You can use the constructor of the above classes to generate the JSON steps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/authorjapps/zerocode/issues/195#issuecomment-479636708, or mute the thread https://github.com/notifications/unsubscribe-auth/AQfIZwX8oJgmu3Zgj9us_HD0B9fxV53Eks5vdQgGgaJpZM4aR0CI .

respondsid avatar Apr 03 '19 20:04 respondsid

I was able to parse the spec

On Wed, Apr 3, 2019, 3:59 PM authorjapps [email protected] wrote:

@respondsid https://github.com/respondsid , Basically our approach could be in this way. Once we figure out how to parse the open-api/swagger spec-json, we have to fit the url, method, request, response to the below two classes

org.jsmart.zerocode.core.domain.Step

org.jsmart.zerocode.core.domain.ScenarioSpec

You can use the constructor of the above classes to generate the JSON steps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/authorjapps/zerocode/issues/195#issuecomment-479636708, or mute the thread https://github.com/notifications/unsubscribe-auth/AQfIZwX8oJgmu3Zgj9us_HD0B9fxV53Eks5vdQgGgaJpZM4aR0CI .

respondsid avatar Apr 03 '19 20:04 respondsid

When we have a working version(which we are close to it already), then we will try to refine it a bit to take the following into account (sometimes later as we proceed). I am just putting them here before it goes from our minds :-)

  • Initial version - Clone the swagger-zerocode-gen repo and run
  • Later - Generate a uber jar(fat jar) and provide command line option

java -jar swagger-zerocode-gen.jar --o all

java -jar swagger-zerocode-gen.jar --o requiredFieldsOnly

java -jar swagger-zerocode-gen.jar --o randomizeRequestFields

java -jar swagger-zerocode-gen.jar --o queryParamSection

etc... We will add more options here as we proceed

  • One additional step with the required fields only, with step name as path_required_fields

One step with all the fields(as usual currently working)

  • To randomize a request field we can generate this way
"name": "${RANDOM.STRING:10}",

"name": "Name ${RANDOM.STRING:10}",

"id": "person_id_${RANDOM.NUMBER}",

authorjapps avatar Apr 07 '19 11:04 authorjapps

@respondsid , Could you please

Join the collaborators mailing list https://groups.google.com/forum/#!members/zerocode-automation

Join Gitter room https://gitter.im/zerocode-testing/help-and-usage

Cheers 👍

authorjapps avatar Apr 09 '19 20:04 authorjapps

Hi Team, i would like to work on this issue. Can any one guide me, how to start

cns45 avatar Aug 24 '19 15:08 cns45

hi all - forking the repo, hopefully will be back here sooner than later with a PR :)

lukecolpo avatar Apr 17 '20 03:04 lukecolpo

@lukecolpo , thanks for your interest 🙏 Can we have a brief chat about the requirements, ACs etc. That might give you a better understanding of the output that will be useful to the end users(developer as well as testers)!

Are you already in Slack ?

authorjapps avatar Apr 23 '20 08:04 authorjapps

@authorjapps sure!!! i've been getting up to speed with the code base as well as the new spec, so i think that'd be a great idea. I'll join the slack

lukecolpo avatar Apr 29 '20 01:04 lukecolpo

@lukecolpo any positive update on this issue or Should I ask @authorjapps to assign this issue to me ?

dhavalshah007 avatar Jun 18 '20 19:06 dhavalshah007

@authorjapps , @santhoshTpixler , @respondsid Is this issue still open. I am using Zerocode for long time, but it will be good if integration with OpenApi will be possible. As it will be make automation faster and without many changes. As OpenApi is well maintained and if we can use it in Zerocode then it's great.

warademilind avatar Aug 11 '21 13:08 warademilind

I was looking for something similar and stumbled on to this. @authorjapps Any positive updates?

SuyogSSS avatar Oct 19 '21 11:10 SuyogSSS

Hi @SuyogSSS , @warademilind , Looks like you bath have different requirements here than the original ticket. Let me know if my assumption is wrong.

Please provide your requirements what exactly you want to do. I will try to help.

I have created space specific to you both(see here(click) ). Please put the details. I will create separate ticket if needed, so not to worry in terms of matching the original ticket.

The original ticket demands very large implementation. Hence this ticket is kept opened and unable to get proper light to see the solution yet.

@warademilind : Put your requirement step by step here what you want to achieve or test.

@SuyogSSS : Put your requirement step by step here what you want to achieve or test.

nirmalchandra avatar Oct 20 '21 10:10 nirmalchandra

@nirmalchandra , please find below example of OpenAPI specification.

https://petstore.swagger.io/

If we can integrate this with Zerocode it will be very useful.

warademilind avatar Mar 01 '23 09:03 warademilind