[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:
Vincent Devos 2019-05-11 05:10:25 +02:00 committed by William Cheng
parent 48314905da
commit 98afbe062b
23 changed files with 709 additions and 266 deletions

View File

@ -52,6 +52,7 @@ declare -a scripts=(
"./bin/elixir-petstore.sh" "./bin/elixir-petstore.sh"
"./bin/go-petstore.sh" "./bin/go-petstore.sh"
"./bin/go-gin-petstore-server.sh" "./bin/go-gin-petstore-server.sh"
"./bin/groovy-petstore.sh"
#"./bin/elm-petstore-all.sh" #"./bin/elm-petstore-all.sh"
"./bin/meta-codegen.sh" "./bin/meta-codegen.sh"
# OTHERS # OTHERS

View File

@ -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| |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| |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| |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|

View File

@ -978,10 +978,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
} }
} }
@Override
public void postProcessParameter(CodegenParameter parameter) {
}
@Override @Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) { public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// recursively add import for mapping one type to multiple imports // recursively add import for mapping one type to multiple imports

View File

@ -17,20 +17,16 @@
package org.openapitools.codegen.languages; package org.openapitools.codegen.languages;
import org.openapitools.codegen.CliOption; import org.openapitools.codegen.*;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Map;
import static org.openapitools.codegen.utils.StringUtils.camelize; import static org.openapitools.codegen.utils.StringUtils.camelize;
public class GroovyClientCodegen extends AbstractJavaCodegen { 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() { public GroovyClientCodegen() {
super(); super();
@ -60,18 +56,14 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
artifactId = "openapi-groovy"; artifactId = "openapi-groovy";
dateLibrary = "legacy"; //TODO: add joda support to 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.SOURCE_FOLDER, this.getSourceFolder());
updateOption(CodegenConstants.INVOKER_PACKAGE, this.getInvokerPackage()); updateOption(CodegenConstants.INVOKER_PACKAGE, this.getInvokerPackage());
updateOption(CodegenConstants.ARTIFACT_ID, this.getArtifactId()); updateOption(CodegenConstants.ARTIFACT_ID, this.getArtifactId());
updateOption(CodegenConstants.API_PACKAGE, apiPackage); updateOption(CodegenConstants.API_PACKAGE, apiPackage);
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage); 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 @Override
@ -86,25 +78,32 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
@Override @Override
public String getHelp() { public String getHelp() {
return "Generates a Groovy API client (beta)."; return "Generates a Groovy API client.";
} }
@Override @Override
public void processOpts() { public void processOpts() {
super.processOpts(); super.processOpts();
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
}
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle")); 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", supportingFiles.add(new SupportingFile("ApiUtils.mustache",
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiUtils.groovy")); (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 @Override
public String toApiName(String name) { public String toApiName(String name) {
if (name.length() == 0) { if (name.length() == 0) {
@ -114,10 +113,6 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
return camelize(name) + "Api"; return camelize(name) + "Api";
} }
public void setConfigPackage(String configPackage) {
this.configPackage = configPackage;
}
@Override @Override
public String escapeQuotationMark(String input) { public String escapeQuotationMark(String input) {
// remove ' to avoid code injection // remove ' to avoid code injection

View File

@ -1,33 +1,38 @@
package {{invokerPackage}}; package {{invokerPackage}}
import groovyx.net.http.HTTPBuilder import static groovyx.net.http.HttpBuilder.configure
import groovyx.net.http.Method import static java.net.URI.create
import static groovyx.net.http.ContentType.JSON
import static java.net.URI.create;
class ApiUtils { 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) def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
println "url=$url uriPath=$uriPath" println "url=$url uriPath=$uriPath"
def http = new HTTPBuilder(url) def http = configure {
http.request( Method.valueOf(method), JSON ) { request.uri = url
uri.path = uriPath request.uri.path = uriPath
uri.query = queryParams }
response.success = { resp, json -> .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) { if (type != null) {
onSuccess(parse(json, container, type)) onSuccess(parse(json, container, type))
} }
} }
response.failure = { resp -> response.failure { resp ->
onFailure(resp.status, resp.statusLine.reasonPhrase) onFailure(resp.statusCode, resp.message)
} }
} }
} }
private static def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
// HTTPBuilder expects to get as its constructor parameter an URL, // HTTPBuilder expects to get as its constructor parameter an URL,
// without any other additions like path, therefore we need to cut the path // without any other additions like path, therefore we need to cut the path
// from the basePath as it is represented by swagger APIs // from the basePath as it is represented by swagger APIs
@ -38,12 +43,11 @@ class ApiUtils {
[basePath-pathOnly, pathOnly+versionPath+resourcePath] [basePath-pathOnly, pathOnly+versionPath+resourcePath]
} }
private def parse(object, container, clazz) {
def parse(object, container, clazz) { if (container == "array") {
if (container == "List") {
return object.collect {parse(it, "", clazz)} return object.collect {parse(it, "", clazz)}
} else { } else {
return clazz.newInstance(object) return clazz.newInstance(object)
} }
} }

View 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}}

View File

@ -1,51 +1,86 @@
package {{package}}; package {{package}};
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import {{invokerPackage}}.ApiUtils import {{invokerPackage}}.ApiUtils
{{#imports}}import {{import}} {{#imports}}import {{import}}
{{/imports}} {{/imports}}
import java.util.*;
@Mixin(ApiUtils)
{{#operations}} {{#operations}}
class {{classname}} { class {{classname}} {
String basePath = "{{{basePath}}}" String basePath = "{{{basePath}}}"
String versionPath = "/api/v1" String versionPath = ""
ApiUtils apiUtils = new ApiUtils();
{{#operation}} {{#operation}}
def {{operationId}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) { def {{operationId}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "{{{path}}}" String resourcePath = "{{{path}}}"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
{{#allParams}} {{#allParams}}{{#required}}
{{#required}}
// verify required params are set // verify required params are set
if ({{paramName}} == null) { if ({{paramName}} == null) {
throw new RuntimeException("missing required params {{paramName}}") throw new RuntimeException("missing required params {{paramName}}")
} }
{{/required}}{{/allParams}}
{{/required}}
{{/allParams}}
{{#queryParams}} {{#queryParams}}
if (!"null".equals(String.valueOf({{paramName}}))) if ({{paramName}} != null) {
queryParams.put("{{baseName}}", String.valueOf({{paramName}})) queryParams.put("{{baseName}}", {{paramName}})
}
{{/queryParams}} {{/queryParams}}
{{#headerParams}} {{#headerParams}}
headerParams.put("{{baseName}}", {{paramName}}) if ({{paramName}} != null) {
headerParams.put("{{baseName}}", {{paramName}})
}
{{/headerParams}} {{/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}}", "{{httpMethod}}", "{{returnContainer}}",
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}}) {{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})

View File

@ -6,6 +6,11 @@ group = '{{groupId}}'
version = '{{artifactVersion}}' version = '{{artifactVersion}}'
archivesBaseName = 'openapi-gen-groovy' archivesBaseName = 'openapi-gen-groovy'
wrapper {
gradleVersion = '4.9'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript { buildscript {
repositories { repositories {
maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' } maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' }
@ -22,19 +27,17 @@ repositories {
ext { ext {
swagger_annotations_version = "1.5.22" swagger_annotations_version = "1.5.22"
jackson_version = "2.8.11" jackson_version = "2.9.8"
jackson_databind_version = "2.8.11.3"
} }
dependencies { 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 "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_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-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.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' 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' }

View File

@ -10,11 +10,8 @@ import {{import}};
@Canonical @Canonical
class {{classname}} { class {{classname}} {
{{#vars}} {{#vars}}
{{#description}} {{#description}}/* {{{description}}} */{{/description}}
/* {{{description}}} */
{{/description}}
{{{dataType}}} {{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}} {{{dataType}}} {{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/vars}} {{/vars}}
} }
{{/model}} {{/model}}

View File

@ -1019,7 +1019,6 @@
<module>samples/client/petstore/dart-jaguar/flutter_petstore/openapi</module>--> <module>samples/client/petstore/dart-jaguar/flutter_petstore/openapi</module>-->
<!--<module>samples/client/petstore/dart2/petstore</module>--> <!--<module>samples/client/petstore/dart2/petstore</module>-->
<module>samples/client/petstore/elm-0.18</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</module>
<module>samples/client/petstore/rust-reqwest</module> <module>samples/client/petstore/rust-reqwest</module>
<!--<module>samples/client/petstore/perl</module>--> <!--<module>samples/client/petstore/perl</module>-->
@ -1096,6 +1095,7 @@
<module>samples/client/petstore/java/resteasy</module> <module>samples/client/petstore/java/resteasy</module>
<module>samples/client/petstore/java/google-api-client</module> <module>samples/client/petstore/java/google-api-client</module>
<module>samples/client/petstore/java/rest-assured</module> <module>samples/client/petstore/java/rest-assured</module>
<module>samples/client/petstore/groovy</module>
<!-- servers --> <!-- servers -->
<module>samples/server/petstore/jaxrs-jersey</module> <module>samples/server/petstore/jaxrs-jersey</module>
<module>samples/server/petstore/jaxrs-spec</module> <module>samples/server/petstore/jaxrs-spec</module>
@ -1176,7 +1176,6 @@
<module>samples/client/petstore/java/vertx</module> <module>samples/client/petstore/java/vertx</module>
<module>samples/client/petstore/java/resteasy</module> <module>samples/client/petstore/java/resteasy</module>
<module>samples/client/petstore/java/google-api-client</module> <module>samples/client/petstore/java/google-api-client</module>
<!-- <module>samples/client/petstore/kotlin/</module> -->
<!-- servers --> <!-- servers -->
<module>samples/server/petstore/jaxrs-jersey</module> <module>samples/server/petstore/jaxrs-jersey</module>
<module>samples/server/petstore/jaxrs-spec</module> <module>samples/server/petstore/jaxrs-spec</module>
@ -1222,6 +1221,9 @@
<module>samples/client/petstore/elixir</module> <module>samples/client/petstore/elixir</module>
<module>samples/client/petstore/erlang-client</module> <module>samples/client/petstore/erlang-client</module>
<module>samples/client/petstore/erlang-proper</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 --> <!-- servers -->
<module>samples/server/petstore/erlang-server</module> <module>samples/server/petstore/erlang-server</module>
<module>samples/server/petstore/jaxrs/jersey2</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</module>
<module>samples/server/petstore/spring-mvc-j8-async</module> <module>samples/server/petstore/spring-mvc-j8-async</module>
<module>samples/server/petstore/spring-mvc-j8-localdatetime</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> </modules>
</profile> </profile>
<!-- test with Haskell --> <!-- test with Haskell -->

View 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}"
};
```

View File

@ -6,6 +6,11 @@ group = 'org.openapitools'
version = '1.0.0' version = '1.0.0'
archivesBaseName = 'openapi-gen-groovy' archivesBaseName = 'openapi-gen-groovy'
wrapper {
gradleVersion = '4.9'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript { buildscript {
repositories { repositories {
maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' } maven { url 'https://repo.jfrog.org/artifactory/gradle-plugins' }
@ -22,19 +27,17 @@ repositories {
ext { ext {
swagger_annotations_version = "1.5.22" swagger_annotations_version = "1.5.22"
jackson_version = "2.8.11" jackson_version = "2.9.8"
jackson_databind_version = "2.8.11.3"
} }
dependencies { 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 "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_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-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.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' 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' }

View File

@ -1,33 +1,38 @@
package org.openapitools.api; package org.openapitools.api
import groovyx.net.http.HTTPBuilder import static groovyx.net.http.HttpBuilder.configure
import groovyx.net.http.Method import static java.net.URI.create
import static groovyx.net.http.ContentType.JSON
import static java.net.URI.create;
class ApiUtils { 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) def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
println "url=$url uriPath=$uriPath" println "url=$url uriPath=$uriPath"
def http = new HTTPBuilder(url) def http = configure {
http.request( Method.valueOf(method), JSON ) { request.uri = url
uri.path = uriPath request.uri.path = uriPath
uri.query = queryParams }
response.success = { resp, json -> .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) { if (type != null) {
onSuccess(parse(json, container, type)) onSuccess(parse(json, container, type))
} }
} }
response.failure = { resp -> response.failure { resp ->
onFailure(resp.status, resp.statusLine.reasonPhrase) onFailure(resp.statusCode, resp.message)
} }
} }
} }
private static def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
// HTTPBuilder expects to get as its constructor parameter an URL, // HTTPBuilder expects to get as its constructor parameter an URL,
// without any other additions like path, therefore we need to cut the path // without any other additions like path, therefore we need to cut the path
// from the basePath as it is represented by swagger APIs // from the basePath as it is represented by swagger APIs
@ -38,12 +43,11 @@ class ApiUtils {
[basePath-pathOnly, pathOnly+versionPath+resourcePath] [basePath-pathOnly, pathOnly+versionPath+resourcePath]
} }
private def parse(object, container, clazz) {
def parse(object, container, clazz) { if (container == "array") {
if (container == "List") {
return object.collect {parse(it, "", clazz)} return object.collect {parse(it, "", clazz)}
} else { } else {
return clazz.newInstance(object) return clazz.newInstance(object)
} }
} }

View File

@ -1,191 +1,278 @@
package org.openapitools.api; 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.api.ApiUtils
import org.openapitools.model.ModelApiResponse import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet import org.openapitools.model.Pet
import java.util.*;
@Mixin(ApiUtils)
class PetApi { class PetApi {
String basePath = "http://petstore.swagger.io/v2" 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) { def addPet ( Pet body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet" String resourcePath = "/pet"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "POST", "",
null ) null )
} }
def deletePet ( Long petId, String apiKey, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (petId == null) { if (petId == null) {
throw new RuntimeException("missing required params petId") 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", "", "DELETE", "",
null ) null )
} }
def findPetsByStatus ( List<String> status, Closure onSuccess, Closure onFailure) { def findPetsByStatus ( List<String> status, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/findByStatus" String resourcePath = "/pet/findByStatus"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (status == null) { if (status == null) {
throw new RuntimeException("missing required params status") throw new RuntimeException("missing required params status")
} }
if (!"null".equals(String.valueOf(status))) if (status != null) {
queryParams.put("status", String.valueOf(status)) 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", "GET", "array",
Pet.class ) Pet.class )
} }
def findPetsByTags ( List<String> tags, Closure onSuccess, Closure onFailure) { def findPetsByTags ( List<String> tags, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/findByTags" String resourcePath = "/pet/findByTags"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (tags == null) { if (tags == null) {
throw new RuntimeException("missing required params tags") throw new RuntimeException("missing required params tags")
} }
if (!"null".equals(String.valueOf(tags))) if (tags != null) {
queryParams.put("tags", String.valueOf(tags)) 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", "GET", "array",
Pet.class ) Pet.class )
} }
def getPetById ( Long petId, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (petId == null) { if (petId == null) {
throw new RuntimeException("missing required params petId") 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", "", "GET", "",
Pet.class ) Pet.class )
} }
def updatePet ( Pet body, Closure onSuccess, Closure onFailure) { def updatePet ( Pet body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet" String resourcePath = "/pet"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "PUT", "",
null ) null )
} }
def updatePetWithForm ( Long petId, String name, String status, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (petId == null) { if (petId == null) {
throw new RuntimeException("missing required params petId") 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", "", "POST", "",
null ) null )
} }
def uploadFile ( Long petId, String additionalMetadata, File file, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (petId == null) { if (petId == null) {
throw new RuntimeException("missing required params petId") 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", "", "POST", "",
ModelApiResponse.class ) ModelApiResponse.class )

View File

@ -1,93 +1,116 @@
package org.openapitools.api; 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.api.ApiUtils
import org.openapitools.model.Order import org.openapitools.model.Order
import java.util.*;
@Mixin(ApiUtils)
class StoreApi { class StoreApi {
String basePath = "http://petstore.swagger.io/v2" 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) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (orderId == null) { if (orderId == null) {
throw new RuntimeException("missing required params orderId") 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", "", "DELETE", "",
null ) null )
} }
def getInventory ( Closure onSuccess, Closure onFailure) { def getInventory ( Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/store/inventory" String resourcePath = "/store/inventory"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] 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", "GET", "map",
Integer.class ) Integer.class )
} }
def getOrderById ( Long orderId, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (orderId == null) { if (orderId == null) {
throw new RuntimeException("missing required params orderId") 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", "", "GET", "",
Order.class ) Order.class )
} }
def placeOrder ( Order body, Closure onSuccess, Closure onFailure) { def placeOrder ( Order body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/store/order" String resourcePath = "/store/order"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "POST", "",
Order.class ) Order.class )

View File

@ -1,193 +1,264 @@
package org.openapitools.api; 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.api.ApiUtils
import java.util.List
import org.openapitools.model.User import org.openapitools.model.User
import java.util.*;
@Mixin(ApiUtils)
class UserApi { class UserApi {
String basePath = "http://petstore.swagger.io/v2" 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) { def createUser ( User body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user" String resourcePath = "/user"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "POST", "",
null ) null )
} }
def createUsersWithArrayInput ( List<User> body, Closure onSuccess, Closure onFailure) { def createUsersWithArrayInput ( List<User> body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/createWithArray" String resourcePath = "/user/createWithArray"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "POST", "",
null ) null )
} }
def createUsersWithListInput ( List<User> body, Closure onSuccess, Closure onFailure) { def createUsersWithListInput ( List<User> body, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/createWithList" String resourcePath = "/user/createWithList"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "POST", "",
null ) null )
} }
def deleteUser ( String username, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (username == null) { if (username == null) {
throw new RuntimeException("missing required params username") 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", "", "DELETE", "",
null ) null )
} }
def getUserByName ( String username, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (username == null) { if (username == null) {
throw new RuntimeException("missing required params username") 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", "", "GET", "",
User.class ) User.class )
} }
def loginUser ( String username, String password, Closure onSuccess, Closure onFailure) { def loginUser ( String username, String password, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/login" String resourcePath = "/user/login"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (username == null) { if (username == null) {
throw new RuntimeException("missing required params username") throw new RuntimeException("missing required params username")
} }
// verify required params are set // verify required params are set
if (password == null) { if (password == null) {
throw new RuntimeException("missing required params password") throw new RuntimeException("missing required params password")
} }
if (!"null".equals(String.valueOf(username))) if (username != null) {
queryParams.put("username", String.valueOf(username)) 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", "", "GET", "",
String.class ) String.class )
} }
def logoutUser ( Closure onSuccess, Closure onFailure) { def logoutUser ( Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/logout" String resourcePath = "/user/logout"
// query params // params
def queryParams = [:] def queryParams = [:]
def headerParams = [:] 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", "", "GET", "",
null ) null )
} }
def updateUser ( String username, User body, Closure onSuccess, Closure onFailure) { 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 queryParams = [:]
def headerParams = [:] def headerParams = [:]
def bodyParams
def contentType
// verify required params are set // verify required params are set
if (username == null) { if (username == null) {
throw new RuntimeException("missing required params username") throw new RuntimeException("missing required params username")
} }
// verify required params are set // verify required params are set
if (body == null) { if (body == null) {
throw new RuntimeException("missing required params body") 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", "", "PUT", "",
null ) null )

View File

@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical @Canonical
class Category { class Category {
Long id Long id
String name String name
} }

View File

@ -6,10 +6,10 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical @Canonical
class ModelApiResponse { class ModelApiResponse {
Integer code Integer code
String type String type
String message String message
} }

View File

@ -6,17 +6,16 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical @Canonical
class Order { class Order {
Long id Long id
Long petId Long petId
Integer quantity Integer quantity
Date shipDate Date shipDate
/* Order Status */ /* Order Status */
String status String status
Boolean complete = false Boolean complete = false
} }

View File

@ -10,17 +10,16 @@ import org.openapitools.model.Tag;
@Canonical @Canonical
class Pet { class Pet {
Long id Long id
Category category = null Category category = null
String name String name
List<String> photoUrls = new ArrayList<String>() List<String> photoUrls = new ArrayList<String>()
List<Tag> tags = new ArrayList<Tag>() List<Tag> tags = new ArrayList<Tag>()
/* pet status in the store */ /* pet status in the store */
String status String status
} }

View File

@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical @Canonical
class Tag { class Tag {
Long id Long id
String name String name
} }

View File

@ -6,21 +6,20 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical @Canonical
class User { class User {
Long id Long id
String username String username
String firstName String firstName
String lastName String lastName
String email String email
String password String password
String phone String phone
/* User Status */ /* User Status */
Integer userStatus Integer userStatus
} }

View File

@ -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)
};
}
}