-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW API CLIENT] Rest-assured (#7492)
* Rest-assured http client has been added 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 * Tests has been added * Doc and tests has been fixed, JSON.mustache moved to common
- Loading branch information
Showing
119 changed files
with
12,368 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"library": "rest-assured", | ||
"artifactId": "swagger-petstore-rest-assured" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
fi | ||
|
||
# if you've executed sbt assembly previously it will use that instead. | ||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Java/libraries/rest-assured -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-rest-assured.json -o samples/client/petstore/java/rest-assured -DhideGenerationTimestamp=true" | ||
|
||
echo "Removing files and folders under samples/client/petstore/java/rest-assured/src/main" | ||
rm -rf samples/client/petstore/java/rest-assured/src/main | ||
find samples/client/petstore/java/rest-assured -maxdepth 1 -type f ! -name "README.md" -exec rm {} + | ||
java $JAVA_OPTS -jar $executable $ags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
modules/swagger-codegen/src/main/resources/Java/libraries/rest-assured/ApiClient.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{{>licenseInfo}} | ||
|
||
package {{invokerPackage}}; | ||
|
||
import {{apiPackage}}.*; | ||
|
||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
|
||
{{^fullJavaUtil}} | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import io.restassured.RestAssured; | ||
import io.restassured.builder.RequestSpecBuilder; | ||
import io.restassured.builder.ResponseSpecBuilder; | ||
import io.restassured.response.Response; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
{{/fullJavaUtil}} | ||
|
||
public class ApiClient { | ||
private final Config config; | ||
private ApiClient(Config config) { | ||
this.config = config; | ||
} | ||
|
||
public static ApiClient api(Config config) { | ||
return new ApiClient(config); | ||
} | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
public {{classname}} {{classVarName}}() { | ||
return {{classname}}.{{classVarName}}(config.baseReqSpec.get()); | ||
} | ||
{{/apis}} | ||
{{/apiInfo}} | ||
|
||
public static class Config { | ||
private Supplier<RequestSpecBuilder> baseReqSpec; | ||
/** | ||
* Use common specification for all operations | ||
*/ | ||
public Config reqSpecSupplier(Supplier<RequestSpecBuilder> supplier) { | ||
this.baseReqSpec = supplier; | ||
return this; | ||
} | ||
|
||
public static Config apiConfig() { | ||
return new Config(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../swagger-codegen/src/main/resources/Java/libraries/rest-assured/GsonObjectMapper.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{{>licenseInfo}} | ||
|
||
package {{invokerPackage}}; | ||
|
||
import io.restassured.mapper.ObjectMapper; | ||
import io.restassured.mapper.ObjectMapperDeserializationContext; | ||
import io.restassured.mapper.ObjectMapperSerializationContext; | ||
|
||
public class GsonObjectMapper implements ObjectMapper { | ||
private JSON json; | ||
private GsonObjectMapper() { | ||
this.json = new JSON(); | ||
} | ||
|
||
public static GsonObjectMapper gson() { | ||
return new GsonObjectMapper(); | ||
} | ||
|
||
@Override | ||
public Object deserialize(ObjectMapperDeserializationContext context) { | ||
return json.deserialize(context.getDataToDeserialize().asString(), context.getType()); | ||
} | ||
|
||
@Override | ||
public Object serialize(ObjectMapperSerializationContext context) { | ||
return json.serialize(context.getObjectToSerialize()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
modules/swagger-codegen/src/main/resources/Java/libraries/rest-assured/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# {{artifactId}} | ||
|
||
## Requirements | ||
|
||
Building the API client library requires [Maven](https://maven.apache.org/) to be installed. | ||
|
||
## Installation & Usage | ||
|
||
To install the API client library to your local Maven repository, simply execute: | ||
|
||
```shell | ||
mvn install | ||
``` | ||
|
||
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: | ||
|
||
```shell | ||
mvn deploy | ||
``` | ||
|
||
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information. | ||
|
||
After the client library is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>{{groupId}}</groupId> | ||
<artifactId>{{artifactId}}</artifactId> | ||
<version>{{artifactVersion}}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
``` | ||
|
||
## Recommendation | ||
|
||
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. | ||
|
||
## Author | ||
|
||
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} | ||
{{/hasMore}}{{/apis}}{{/apiInfo}} | ||
|
31 changes: 31 additions & 0 deletions
31
...gger-codegen/src/main/resources/Java/libraries/rest-assured/ResponseSpecBuilders.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{>licenseInfo}} | ||
|
||
package {{invokerPackage}}; | ||
|
||
import io.restassured.builder.ResponseSpecBuilder; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.ResponseSpecification; | ||
|
||
import java.util.function.Function; | ||
|
||
public class ResponseSpecBuilders { | ||
private ResponseSpecBuilders() { | ||
} | ||
|
||
public static Function<Response, Response> validatedWith(ResponseSpecification respSpec) { | ||
return response -> response.then().spec(respSpec).extract().response(); | ||
} | ||
|
||
public static Function<Response, Response> validatedWith(ResponseSpecBuilder respSpec) { | ||
return validatedWith(respSpec.build()); | ||
} | ||
|
||
/** | ||
* @param code expected status code | ||
* @return ResponseSpecBuilder | ||
*/ | ||
public static ResponseSpecBuilder shouldBeCode(int code) { | ||
return new ResponseSpecBuilder().expectStatusCode(code); | ||
} | ||
} |
Oops, something went wrong.