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

[NEW API CLIENT] Java Rest-assured #7492

Merged
merged 3 commits into from
Jan 28, 2018
Merged

Conversation

viclovsky
Copy link
Contributor

@viclovsky viclovsky commented Jan 24, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

There is a new API client. It can be used, for instance, for regression testing.
It based on rest-assured library: https://github.com/rest-assured/rest-assured
It is good for positive tests as well as negative.
I was inspired by RARC project: https://github.com/qameta/rarc

Added necessary tests.
Note: Java6 support will be in next PR

@@ -246,6 +248,11 @@ public void processOpts() {
supportingFiles.remove(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
} else if ("google-api-client".equals(getLibrary())) {
additionalProperties.put("jackson", "true");

} else if (REST_ASSURED.equals(getLibrary())) {
additionalProperties.put("java8", "true");
Copy link
Contributor

@cbornet cbornet Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be hard to make it compatible with java6 ? That way it could be used on android.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially this client is supposed to be comatible with java8 and supporting java6 would mean rewriting most of the functions, which are used by client.

*/
@Test
public void shouldSee405AfterAddPet() {
Pet body = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The petstore samples should include actual tests against the petstore server to verify the generated code in CI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. I did it in c698765


package {{invokerPackage}};

import com.google.gson.Gson;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template should be put in common with okhttp-gson

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ApiClient has been added

@deprecated has been added for operation

{{{returnType}}} has been fixed

build.gradle.mustache, build.sbt.mustache, api_doc_mustache has been added

Samples has been added for rest-assured

Useless supporting files has been removed for rest-assured

Sample has been added for rest-assured
@wing328
Copy link
Contributor

wing328 commented Jan 28, 2018

@viclovsky I did some tests locally and the result is good. Thanks for your contribution.

@wing328 wing328 merged commit 6debf74 into swagger-api:master Jan 28, 2018
@wing328
Copy link
Contributor

wing328 commented Jan 28, 2018

Added to CircleCI Java8 tests via 6bc84ee

@wing328 wing328 changed the title [NEW API CLIENT] Rest-assured [NEW API CLIENT] Java Rest-assured Jan 28, 2018
@asaravindkumar
Copy link

This is great! Can you point me to a sample that I can refer to try this?

@viclovsky
Copy link
Contributor Author

Hi @asaravindkumar!

I have done a project https://github.com/viclovsky/swagger-rest-assured-example where I used swagger code generation. To my mind you can use it for experiments.. Moreover swagger-codegen project has tests examples for the client: https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/java/rest-assured.

Just for information: I am planning to add ability to customize mapper but it will be available after rest-assured 3.0.8 release.

@kuldeepkumar1989
Copy link

Hi @viclovsky, i cloned the project (https://github.com/viclovsky/swagger-rest-assured-example), during mvn clean install it showing error . example-api-client/target/generated-sources/swagger/src/main/java/ru/vicdev/example/swagger/client/api/PetApi.java:[258,36] no suitable method found for as(java.lang.reflect.Type)
method io.restassured.response.ResponseBodyExtractionOptions.as(java.lang.Class) is not applicable

@viclovsky
Copy link
Contributor Author

Hi @kuldeepkumar1989, my project had old version rest-assured (3.0.6). It has been updated now.

@hunzai
Copy link

hunzai commented Sep 2, 2018

This is great guys. Thanks @viclovsky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants