mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[GROOVY] update client generator to a stable version (#2847)
* [GROOVY] update client generator to a stable version * fix tab * fix remove using invokerPackage * fix test
This commit is contained in:
parent
48314905da
commit
98afbe062b
@ -52,6 +52,7 @@ declare -a scripts=(
|
||||
"./bin/elixir-petstore.sh"
|
||||
"./bin/go-petstore.sh"
|
||||
"./bin/go-gin-petstore-server.sh"
|
||||
"./bin/groovy-petstore.sh"
|
||||
#"./bin/elm-petstore-all.sh"
|
||||
"./bin/meta-codegen.sh"
|
||||
# OTHERS
|
||||
|
@ -42,4 +42,3 @@ sidebar_label: groovy
|
||||
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|
||||
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|
||||
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd><dl>|null|
|
||||
|configPackage|configuration package for generated code| |org.openapitools.configuration|
|
||||
|
@ -978,10 +978,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// recursively add import for mapping one type to multiple imports
|
||||
|
@ -17,20 +17,16 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
|
||||
public class GroovyClientCodegen extends AbstractJavaCodegen {
|
||||
public static final String CONFIG_PACKAGE = "configPackage";
|
||||
protected String title = "Petstore Server";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
|
||||
public GroovyClientCodegen() {
|
||||
super();
|
||||
@ -60,18 +56,14 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
|
||||
artifactId = "openapi-groovy";
|
||||
dateLibrary = "legacy"; //TODO: add joda support to groovy
|
||||
|
||||
// clioOptions default redifinition need to be updated
|
||||
// clioOptions default redefinition need to be updated
|
||||
updateOption(CodegenConstants.SOURCE_FOLDER, this.getSourceFolder());
|
||||
updateOption(CodegenConstants.INVOKER_PACKAGE, this.getInvokerPackage());
|
||||
updateOption(CodegenConstants.ARTIFACT_ID, this.getArtifactId());
|
||||
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
updateOption(this.DATE_LIBRARY, this.getDateLibrary());
|
||||
updateOption(DATE_LIBRARY, this.getDateLibrary());
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||
|
||||
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code").defaultValue(this.configPackage));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,25 +78,32 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Groovy API client (beta).";
|
||||
return "Generates a Groovy API client.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
|
||||
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
// TODO readme to be added later
|
||||
//supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiUtils.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiUtils.groovy"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> operations, List<Object> allModels) {
|
||||
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
||||
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
|
||||
for (CodegenOperation op : ops) {
|
||||
// Overwrite path to map variable with path parameters
|
||||
op.path = op.path.replace("{", "${");
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
@ -114,10 +113,6 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
public void setConfigPackage(String configPackage) {
|
||||
this.configPackage = configPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove ' to avoid code injection
|
||||
|
@ -1,33 +1,38 @@
|
||||
package {{invokerPackage}};
|
||||
package {{invokerPackage}}
|
||||
|
||||
import groovyx.net.http.HTTPBuilder
|
||||
import groovyx.net.http.Method
|
||||
|
||||
import static groovyx.net.http.ContentType.JSON
|
||||
import static java.net.URI.create;
|
||||
import static groovyx.net.http.HttpBuilder.configure
|
||||
import static java.net.URI.create
|
||||
|
||||
class ApiUtils {
|
||||
|
||||
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, method, container, type) {
|
||||
void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, method, container, type) {
|
||||
def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
|
||||
println "url=$url uriPath=$uriPath"
|
||||
def http = new HTTPBuilder(url)
|
||||
http.request( Method.valueOf(method), JSON ) {
|
||||
uri.path = uriPath
|
||||
uri.query = queryParams
|
||||
response.success = { resp, json ->
|
||||
def http = configure {
|
||||
request.uri = url
|
||||
request.uri.path = uriPath
|
||||
}
|
||||
.invokeMethod(String.valueOf(method).toLowerCase()) {
|
||||
request.uri.query = queryParams
|
||||
request.headers = headerParams
|
||||
if (bodyParams != null) {
|
||||
request.body = bodyParams
|
||||
}
|
||||
request.contentType = contentType
|
||||
|
||||
response.success { resp, json ->
|
||||
if (type != null) {
|
||||
onSuccess(parse(json, container, type))
|
||||
}
|
||||
}
|
||||
response.failure = { resp ->
|
||||
onFailure(resp.status, resp.statusLine.reasonPhrase)
|
||||
response.failure { resp ->
|
||||
onFailure(resp.statusCode, resp.message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
private static def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
// HTTPBuilder expects to get as its constructor parameter an URL,
|
||||
// without any other additions like path, therefore we need to cut the path
|
||||
// from the basePath as it is represented by swagger APIs
|
||||
@ -38,12 +43,11 @@ class ApiUtils {
|
||||
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
||||
}
|
||||
|
||||
|
||||
def parse(object, container, clazz) {
|
||||
if (container == "List") {
|
||||
private def parse(object, container, clazz) {
|
||||
if (container == "array") {
|
||||
return object.collect {parse(it, "", clazz)}
|
||||
} else {
|
||||
return clazz.newInstance(object)
|
||||
return clazz.newInstance(object)
|
||||
}
|
||||
}
|
||||
|
||||
|
62
modules/openapi-generator/src/main/resources/Groovy/README.mustache
vendored
Normal file
62
modules/openapi-generator/src/main/resources/Groovy/README.mustache
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# {{packageName}}
|
||||
|
||||
{{#appDescription}}
|
||||
{{{appDescription}}}
|
||||
{{/appDescription}}
|
||||
|
||||
This Groovy package, using the [http-builder-ng library](https://http-builder-ng.github.io/http-builder-ng/), is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
|
||||
- API version: {{appVersion}}
|
||||
{{#artifactVersion}}
|
||||
- Package version: {{artifactVersion}}
|
||||
{{/artifactVersion}}
|
||||
{{^hideGenerationTimestamp}}
|
||||
- Build date: {{generatedDate}}
|
||||
{{/hideGenerationTimestamp}}
|
||||
- Build package: {{generatorClass}}
|
||||
{{#infoUrl}}
|
||||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||
{{/infoUrl}}
|
||||
|
||||
## Requirements
|
||||
|
||||
* Groovy 2.5.9
|
||||
* Gradle 4.9
|
||||
|
||||
## Build
|
||||
|
||||
First, create the gradle wrapper script:
|
||||
|
||||
```
|
||||
gradle wrapper
|
||||
```
|
||||
|
||||
Then, run:
|
||||
|
||||
```
|
||||
./gradlew check assemble
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
|
||||
```groovy
|
||||
def apiInstance = new {{classname}}()
|
||||
{{#allParams}}def {{paramName}} = {{{example}}} // {{{dataType}}} | {{{description}}}
|
||||
{{/allParams}}
|
||||
|
||||
apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
// on success
|
||||
{{#returnType}}def result = ({{returnType}})it
|
||||
println result
|
||||
{{/returnType}}
|
||||
{{^returnType}}println it{{/returnType}}
|
||||
}
|
||||
{
|
||||
// on failure
|
||||
statusCode, message ->
|
||||
println "${statusCode} ${message}"
|
||||
};
|
||||
```
|
||||
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
|
@ -1,51 +1,86 @@
|
||||
package {{package}};
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
import {{invokerPackage}}.ApiUtils
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
{{#operations}}
|
||||
class {{classname}} {
|
||||
String basePath = "{{{basePath}}}"
|
||||
String versionPath = "/api/v1"
|
||||
String versionPath = ""
|
||||
ApiUtils apiUtils = new ApiUtils();
|
||||
|
||||
{{#operation}}
|
||||
def {{operationId}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "{{{path}}}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
{{#allParams}}{{#required}}
|
||||
// verify required params are set
|
||||
if ({{paramName}} == null) {
|
||||
throw new RuntimeException("missing required params {{paramName}}")
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
{{#queryParams}}
|
||||
if (!"null".equals(String.valueOf({{paramName}})))
|
||||
queryParams.put("{{baseName}}", String.valueOf({{paramName}}))
|
||||
|
||||
if ({{paramName}} != null) {
|
||||
queryParams.put("{{baseName}}", {{paramName}})
|
||||
}
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}
|
||||
headerParams.put("{{baseName}}", {{paramName}})
|
||||
|
||||
if ({{paramName}} != null) {
|
||||
headerParams.put("{{baseName}}", {{paramName}})
|
||||
}
|
||||
{{/headerParams}}
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
{{#bodyParam}}
|
||||
{{^consumes}}
|
||||
contentType = 'application/json';
|
||||
{{/consumes}}
|
||||
{{#consumes.0}}
|
||||
contentType = '{{{mediaType}}}';
|
||||
{{/consumes.0}}
|
||||
{{/bodyParam}}
|
||||
{{#bodyParams}}
|
||||
// only one body parameter
|
||||
if (1 == {{bodyParams.size}}) {
|
||||
bodyParams = {{paramName}}
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("{{baseName}}", {{paramName}})
|
||||
}
|
||||
{{/bodyParams}}
|
||||
|
||||
{{#hasFormParams}}
|
||||
{{#consumes.0}}
|
||||
contentType = '{{{mediaType}}}';
|
||||
{{/consumes.0}}
|
||||
{{#formParams.0}}
|
||||
// only one form parameter
|
||||
if (1 == {{formParams.size}}) {
|
||||
bodyParams = {{paramName}}
|
||||
}
|
||||
// array of form parameters
|
||||
else {
|
||||
bodyParams = [:]
|
||||
}
|
||||
{{/formParams.0}}
|
||||
{{#formParams}}
|
||||
// array of form parameters
|
||||
if (1 < {{formParams.size}}) {
|
||||
bodyParams.put("{{baseName}}", {{paramName}})
|
||||
}
|
||||
{{/formParams}}
|
||||
{{/hasFormParams}}
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"{{httpMethod}}", "{{returnContainer}}",
|
||||
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
|
||||
|
||||
|
@ -6,6 +6,11 @@ group = '{{groupId}}'
|
||||
version = '{{artifactVersion}}'
|
||||
archivesBaseName = 'openapi-gen-groovy'
|
||||
|
||||
wrapper {
|
||||
gradleVersion = '4.9'
|
||||
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' }
|
||||
@ -22,19 +27,17 @@ repositories {
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.22"
|
||||
jackson_version = "2.8.11"
|
||||
jackson_databind_version = "2.8.11.3"
|
||||
jackson_version = "2.9.8"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.codehaus.groovy:groovy-all:2.4.6'
|
||||
compile 'org.codehaus.groovy:groovy-all:2.5.6'
|
||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile 'io.github.http-builder-ng:http-builder-ng-core:1.0.3'
|
||||
testCompile "junit:junit:4.11"
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
||||
|
@ -10,11 +10,8 @@ import {{import}};
|
||||
@Canonical
|
||||
class {{classname}} {
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/* {{{description}}} */
|
||||
{{/description}}
|
||||
{{#description}}/* {{{description}}} */{{/description}}
|
||||
{{{dataType}}} {{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
|
||||
|
||||
{{/vars}}
|
||||
}
|
||||
{{/model}}
|
||||
|
9
pom.xml
9
pom.xml
@ -1019,7 +1019,6 @@
|
||||
<module>samples/client/petstore/dart-jaguar/flutter_petstore/openapi</module>-->
|
||||
<!--<module>samples/client/petstore/dart2/petstore</module>-->
|
||||
<module>samples/client/petstore/elm-0.18</module>
|
||||
<module>samples/client/petstore/groovy</module>
|
||||
<module>samples/client/petstore/rust</module>
|
||||
<module>samples/client/petstore/rust-reqwest</module>
|
||||
<!--<module>samples/client/petstore/perl</module>-->
|
||||
@ -1096,6 +1095,7 @@
|
||||
<module>samples/client/petstore/java/resteasy</module>
|
||||
<module>samples/client/petstore/java/google-api-client</module>
|
||||
<module>samples/client/petstore/java/rest-assured</module>
|
||||
<module>samples/client/petstore/groovy</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
@ -1176,7 +1176,6 @@
|
||||
<module>samples/client/petstore/java/vertx</module>
|
||||
<module>samples/client/petstore/java/resteasy</module>
|
||||
<module>samples/client/petstore/java/google-api-client</module>
|
||||
<!-- <module>samples/client/petstore/kotlin/</module> -->
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
@ -1222,6 +1221,9 @@
|
||||
<module>samples/client/petstore/elixir</module>
|
||||
<module>samples/client/petstore/erlang-client</module>
|
||||
<module>samples/client/petstore/erlang-proper</module>
|
||||
<module>samples/client/petstore/kotlin/</module>
|
||||
<module>samples/client/petstore/kotlin-threetenbp/</module>
|
||||
<module>samples/client/petstore/kotlin-string/</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/erlang-server</module>
|
||||
<module>samples/server/petstore/jaxrs/jersey2</module>
|
||||
@ -1229,9 +1231,6 @@
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
<module>samples/server/petstore/spring-mvc-j8-async</module>
|
||||
<module>samples/server/petstore/spring-mvc-j8-localdatetime</module>
|
||||
<module>samples/client/petstore/kotlin/</module>
|
||||
<module>samples/client/petstore/kotlin-threetenbp/</module>
|
||||
<module>samples/client/petstore/kotlin-string/</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<!-- test with Haskell -->
|
||||
|
48
samples/client/petstore/groovy/README.md
Normal file
48
samples/client/petstore/groovy/README.md
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
This Groovy package, using the [http-builder-ng library](https://http-builder-ng.github.io/http-builder-ng/), is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Build package: org.openapitools.codegen.languages.GroovyClientCodegen
|
||||
|
||||
## Requirements
|
||||
|
||||
* Groovy 2.5.9
|
||||
* Gradle 4.9
|
||||
|
||||
## Build
|
||||
|
||||
First, create the gradle wrapper script:
|
||||
|
||||
```
|
||||
gradle wrapper
|
||||
```
|
||||
|
||||
Then, run:
|
||||
|
||||
```
|
||||
./gradlew check assemble
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
```groovy
|
||||
def apiInstance = new PetApi()
|
||||
def body = new Pet() // Pet | Pet object that needs to be added to the store
|
||||
|
||||
apiInstance.addPet(body)
|
||||
{
|
||||
// on success
|
||||
println it
|
||||
}
|
||||
{
|
||||
// on failure
|
||||
statusCode, message ->
|
||||
println "${statusCode} ${message}"
|
||||
};
|
||||
```
|
||||
|
@ -6,6 +6,11 @@ group = 'org.openapitools'
|
||||
version = '1.0.0'
|
||||
archivesBaseName = 'openapi-gen-groovy'
|
||||
|
||||
wrapper {
|
||||
gradleVersion = '4.9'
|
||||
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' }
|
||||
@ -22,19 +27,17 @@ repositories {
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.22"
|
||||
jackson_version = "2.8.11"
|
||||
jackson_databind_version = "2.8.11.3"
|
||||
jackson_version = "2.9.8"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.codehaus.groovy:groovy-all:2.4.6'
|
||||
compile 'org.codehaus.groovy:groovy-all:2.5.6'
|
||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile 'io.github.http-builder-ng:http-builder-ng-core:1.0.3'
|
||||
testCompile "junit:junit:4.11"
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
||||
|
@ -1,33 +1,38 @@
|
||||
package org.openapitools.api;
|
||||
package org.openapitools.api
|
||||
|
||||
import groovyx.net.http.HTTPBuilder
|
||||
import groovyx.net.http.Method
|
||||
|
||||
import static groovyx.net.http.ContentType.JSON
|
||||
import static java.net.URI.create;
|
||||
import static groovyx.net.http.HttpBuilder.configure
|
||||
import static java.net.URI.create
|
||||
|
||||
class ApiUtils {
|
||||
|
||||
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, method, container, type) {
|
||||
void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, method, container, type) {
|
||||
def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
|
||||
println "url=$url uriPath=$uriPath"
|
||||
def http = new HTTPBuilder(url)
|
||||
http.request( Method.valueOf(method), JSON ) {
|
||||
uri.path = uriPath
|
||||
uri.query = queryParams
|
||||
response.success = { resp, json ->
|
||||
def http = configure {
|
||||
request.uri = url
|
||||
request.uri.path = uriPath
|
||||
}
|
||||
.invokeMethod(String.valueOf(method).toLowerCase()) {
|
||||
request.uri.query = queryParams
|
||||
request.headers = headerParams
|
||||
if (bodyParams != null) {
|
||||
request.body = bodyParams
|
||||
}
|
||||
request.contentType = contentType
|
||||
|
||||
response.success { resp, json ->
|
||||
if (type != null) {
|
||||
onSuccess(parse(json, container, type))
|
||||
}
|
||||
}
|
||||
response.failure = { resp ->
|
||||
onFailure(resp.status, resp.statusLine.reasonPhrase)
|
||||
response.failure { resp ->
|
||||
onFailure(resp.statusCode, resp.message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
private static def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
// HTTPBuilder expects to get as its constructor parameter an URL,
|
||||
// without any other additions like path, therefore we need to cut the path
|
||||
// from the basePath as it is represented by swagger APIs
|
||||
@ -38,12 +43,11 @@ class ApiUtils {
|
||||
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
||||
}
|
||||
|
||||
|
||||
def parse(object, container, clazz) {
|
||||
if (container == "List") {
|
||||
private def parse(object, container, clazz) {
|
||||
if (container == "array") {
|
||||
return object.collect {parse(it, "", clazz)}
|
||||
} else {
|
||||
return clazz.newInstance(object)
|
||||
return clazz.newInstance(object)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,191 +1,278 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
import org.openapitools.api.ApiUtils
|
||||
|
||||
import org.openapitools.model.ModelApiResponse
|
||||
import org.openapitools.model.Pet
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
class PetApi {
|
||||
String basePath = "http://petstore.swagger.io/v2"
|
||||
String versionPath = "/api/v1"
|
||||
String versionPath = ""
|
||||
ApiUtils apiUtils = new ApiUtils();
|
||||
|
||||
def addPet ( Pet body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def deletePet ( Long petId, String apiKey, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/{petId}"
|
||||
String resourcePath = "/pet/${petId}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (petId == null) {
|
||||
throw new RuntimeException("missing required params petId")
|
||||
}
|
||||
|
||||
|
||||
headerParams.put("api_key", apiKey)
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
if (apiKey != null) {
|
||||
headerParams.put("api_key", apiKey)
|
||||
}
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"DELETE", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def findPetsByStatus ( List<String> status, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/findByStatus"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (status == null) {
|
||||
throw new RuntimeException("missing required params status")
|
||||
}
|
||||
|
||||
|
||||
if (!"null".equals(String.valueOf(status)))
|
||||
queryParams.put("status", String.valueOf(status))
|
||||
if (status != null) {
|
||||
queryParams.put("status", status)
|
||||
}
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "array",
|
||||
Pet.class )
|
||||
|
||||
}
|
||||
|
||||
def findPetsByTags ( List<String> tags, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/findByTags"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (tags == null) {
|
||||
throw new RuntimeException("missing required params tags")
|
||||
}
|
||||
|
||||
|
||||
if (!"null".equals(String.valueOf(tags)))
|
||||
queryParams.put("tags", String.valueOf(tags))
|
||||
if (tags != null) {
|
||||
queryParams.put("tags", tags)
|
||||
}
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "array",
|
||||
Pet.class )
|
||||
|
||||
}
|
||||
|
||||
def getPetById ( Long petId, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/{petId}"
|
||||
String resourcePath = "/pet/${petId}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (petId == null) {
|
||||
throw new RuntimeException("missing required params petId")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "",
|
||||
Pet.class )
|
||||
|
||||
}
|
||||
|
||||
def updatePet ( Pet body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"PUT", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def updatePetWithForm ( Long petId, String name, String status, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/{petId}"
|
||||
String resourcePath = "/pet/${petId}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (petId == null) {
|
||||
throw new RuntimeException("missing required params petId")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
contentType = 'application/x-www-form-urlencoded';
|
||||
// only one form parameter
|
||||
if (1 == 2) {
|
||||
bodyParams = name
|
||||
}
|
||||
// array of form parameters
|
||||
else {
|
||||
bodyParams = [:]
|
||||
}
|
||||
// array of form parameters
|
||||
if (1 < 2) {
|
||||
bodyParams.put("name", name)
|
||||
}
|
||||
// array of form parameters
|
||||
if (1 < 2) {
|
||||
bodyParams.put("status", status)
|
||||
}
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def uploadFile ( Long petId, String additionalMetadata, File file, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/pet/{petId}/uploadImage"
|
||||
String resourcePath = "/pet/${petId}/uploadImage"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (petId == null) {
|
||||
throw new RuntimeException("missing required params petId")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
contentType = 'multipart/form-data';
|
||||
// only one form parameter
|
||||
if (1 == 2) {
|
||||
bodyParams = additionalMetadata
|
||||
}
|
||||
// array of form parameters
|
||||
else {
|
||||
bodyParams = [:]
|
||||
}
|
||||
// array of form parameters
|
||||
if (1 < 2) {
|
||||
bodyParams.put("additionalMetadata", additionalMetadata)
|
||||
}
|
||||
// array of form parameters
|
||||
if (1 < 2) {
|
||||
bodyParams.put("file", file)
|
||||
}
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
ModelApiResponse.class )
|
||||
|
||||
|
@ -1,93 +1,116 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
import org.openapitools.api.ApiUtils
|
||||
|
||||
import org.openapitools.model.Order
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
class StoreApi {
|
||||
String basePath = "http://petstore.swagger.io/v2"
|
||||
String versionPath = "/api/v1"
|
||||
String versionPath = ""
|
||||
ApiUtils apiUtils = new ApiUtils();
|
||||
|
||||
def deleteOrder ( String orderId, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/store/order/{orderId}"
|
||||
String resourcePath = "/store/order/${orderId}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (orderId == null) {
|
||||
throw new RuntimeException("missing required params orderId")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"DELETE", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def getInventory ( Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/store/inventory"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "map",
|
||||
Integer.class )
|
||||
|
||||
}
|
||||
|
||||
def getOrderById ( Long orderId, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/store/order/{orderId}"
|
||||
String resourcePath = "/store/order/${orderId}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (orderId == null) {
|
||||
throw new RuntimeException("missing required params orderId")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "",
|
||||
Order.class )
|
||||
|
||||
}
|
||||
|
||||
def placeOrder ( Order body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/store/order"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
Order.class )
|
||||
|
||||
|
@ -1,193 +1,264 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
import org.openapitools.api.ApiUtils
|
||||
|
||||
import java.util.List
|
||||
import org.openapitools.model.User
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
class UserApi {
|
||||
String basePath = "http://petstore.swagger.io/v2"
|
||||
String versionPath = "/api/v1"
|
||||
String versionPath = ""
|
||||
ApiUtils apiUtils = new ApiUtils();
|
||||
|
||||
def createUser ( User body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def createUsersWithArrayInput ( List<User> body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/createWithArray"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def createUsersWithListInput ( List<User> body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/createWithList"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"POST", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def deleteUser ( String username, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/{username}"
|
||||
String resourcePath = "/user/${username}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (username == null) {
|
||||
throw new RuntimeException("missing required params username")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"DELETE", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def getUserByName ( String username, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/{username}"
|
||||
String resourcePath = "/user/${username}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (username == null) {
|
||||
throw new RuntimeException("missing required params username")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "",
|
||||
User.class )
|
||||
|
||||
}
|
||||
|
||||
def loginUser ( String username, String password, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/login"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (username == null) {
|
||||
throw new RuntimeException("missing required params username")
|
||||
}
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (password == null) {
|
||||
throw new RuntimeException("missing required params password")
|
||||
}
|
||||
|
||||
|
||||
if (!"null".equals(String.valueOf(username)))
|
||||
queryParams.put("username", String.valueOf(username))
|
||||
if (username != null) {
|
||||
queryParams.put("username", username)
|
||||
}
|
||||
if (password != null) {
|
||||
queryParams.put("password", password)
|
||||
}
|
||||
|
||||
if (!"null".equals(String.valueOf(password)))
|
||||
queryParams.put("password", String.valueOf(password))
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "",
|
||||
String.class )
|
||||
|
||||
}
|
||||
|
||||
def logoutUser ( Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/logout"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"GET", "",
|
||||
null )
|
||||
|
||||
}
|
||||
|
||||
def updateUser ( String username, User body, Closure onSuccess, Closure onFailure) {
|
||||
// create path and map path parameters (TODO)
|
||||
String resourcePath = "/user/{username}"
|
||||
String resourcePath = "/user/${username}"
|
||||
|
||||
// query params
|
||||
// params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
def bodyParams
|
||||
def contentType
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (username == null) {
|
||||
throw new RuntimeException("missing required params username")
|
||||
}
|
||||
|
||||
|
||||
// verify required params are set
|
||||
if (body == null) {
|
||||
throw new RuntimeException("missing required params body")
|
||||
}
|
||||
|
||||
|
||||
// TODO: form params, body param not yet support
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
|
||||
contentType = 'application/json';
|
||||
// only one body parameter
|
||||
if (1 == 1) {
|
||||
bodyParams = body
|
||||
}
|
||||
// array of body parameters
|
||||
else {
|
||||
bodyParams.put("body", body)
|
||||
}
|
||||
|
||||
|
||||
apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType,
|
||||
"PUT", "",
|
||||
null )
|
||||
|
||||
|
@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@Canonical
|
||||
class Category {
|
||||
|
||||
Long id
|
||||
|
||||
|
||||
String name
|
||||
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@Canonical
|
||||
class ModelApiResponse {
|
||||
|
||||
Integer code
|
||||
|
||||
|
||||
String type
|
||||
|
||||
|
||||
String message
|
||||
|
||||
}
|
||||
|
@ -6,17 +6,16 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@Canonical
|
||||
class Order {
|
||||
|
||||
Long id
|
||||
|
||||
|
||||
Long petId
|
||||
|
||||
|
||||
Integer quantity
|
||||
|
||||
|
||||
Date shipDate
|
||||
|
||||
/* Order Status */
|
||||
String status
|
||||
|
||||
|
||||
Boolean complete = false
|
||||
|
||||
}
|
||||
|
@ -10,17 +10,16 @@ import org.openapitools.model.Tag;
|
||||
|
||||
@Canonical
|
||||
class Pet {
|
||||
|
||||
Long id
|
||||
|
||||
|
||||
Category category = null
|
||||
|
||||
|
||||
String name
|
||||
|
||||
|
||||
List<String> photoUrls = new ArrayList<String>()
|
||||
|
||||
|
||||
List<Tag> tags = new ArrayList<Tag>()
|
||||
|
||||
/* pet status in the store */
|
||||
String status
|
||||
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@Canonical
|
||||
class Tag {
|
||||
|
||||
Long id
|
||||
|
||||
|
||||
String name
|
||||
|
||||
}
|
||||
|
@ -6,21 +6,20 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@Canonical
|
||||
class User {
|
||||
|
||||
Long id
|
||||
|
||||
|
||||
String username
|
||||
|
||||
|
||||
String firstName
|
||||
|
||||
|
||||
String lastName
|
||||
|
||||
|
||||
String email
|
||||
|
||||
|
||||
String password
|
||||
|
||||
|
||||
String phone
|
||||
|
||||
/* User Status */
|
||||
Integer userStatus
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,119 @@
|
||||
package openapitools
|
||||
|
||||
import org.junit.Test
|
||||
import org.openapitools.api.PetApi
|
||||
import org.openapitools.model.Category
|
||||
import org.openapitools.model.Pet
|
||||
import org.openapitools.model.Tag
|
||||
|
||||
|
||||
class PetApiTest extends GroovyTestCase {
|
||||
|
||||
Long petId = 10009;
|
||||
PetApi petApi = new PetApi()
|
||||
|
||||
@Test
|
||||
void testAddAndGetPet() {
|
||||
def pet = new Pet()
|
||||
pet.setId(this.petId)
|
||||
pet.setName("groovy client test")
|
||||
pet.setPhotoUrls(["http://test_groovy_unit_test.com"])
|
||||
pet.setCategory(new Category(this.petId, "test groovy category"))
|
||||
pet.setTags([new Tag(this.petId, "test groovy tag")])
|
||||
this.petApi.addPet(pet) {
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
this.petApi.getPetById(this.petId) {
|
||||
def petGetted = (Pet)it
|
||||
assertEquals(this.petId, petGetted.getId())
|
||||
assertEquals("groovy client test", petGetted.getName())
|
||||
assertEquals(this.petId, petGetted.getCategory().getId())
|
||||
assertEquals("test groovy category", petGetted.getCategory().getName())
|
||||
assertEquals(this.petId, petGetted.getTags()[0].id)
|
||||
assertEquals("test groovy tag", petGetted.getTags()[0].name)
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateOnePet() {
|
||||
def pet = new Pet()
|
||||
pet.setId(this.petId)
|
||||
pet.setName("groovy client updatetest")
|
||||
pet.setStatus("pending")
|
||||
this.petApi.updatePet(pet) {
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
this.petApi.getPetById(this.petId) {
|
||||
def petGetted = (Pet)it
|
||||
assertEquals(this.petId, petGetted.getId())
|
||||
assertEquals("groovy client updatetest", petGetted.getName())
|
||||
assertEquals("pending", petGetted.getStatus())
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
this.petApi.updatePetWithForm(this.petId, "groovy client updatetestwithform", "sold") {
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
this.petApi.getPetById(this.petId) {
|
||||
def petGetted = (Pet)it
|
||||
assertEquals(this.petId, petGetted.getId())
|
||||
assertEquals("groovy client updatetestwithform", petGetted.getName())
|
||||
assertEquals("sold", petGetted.getStatus())
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
this.petApi.deletePet(this.petId, "apiKey") {
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
// should throw a 404 after delete
|
||||
this.petApi.getPetById(this.petId) {
|
||||
assertEquals(404, 200)
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(404, statusCode)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPetByStatus() {
|
||||
this.petApi.findPetsByStatus(["sold"]) {
|
||||
def listPets = (ArrayList)it
|
||||
assertTrue(listPets.size() > 0)
|
||||
}
|
||||
{
|
||||
statusCode, message ->
|
||||
assertEquals(200, statusCode)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user