diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date
index 11d19b0e8ab..c2e38093de4 100755
--- a/bin/utils/ensure-up-to-date
+++ b/bin/utils/ensure-up-to-date
@@ -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
diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md
index 7719a72dcc9..16d4e284a1e 100644
--- a/docs/generators/groovy.md
+++ b/docs/generators/groovy.md
@@ -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.|
**true** Use a SnapShot Version **false** Use a Release Version |null|
-|configPackage|configuration package for generated code| |org.openapitools.configuration|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
index 6a1f6460ea9..3c4ec0102c8 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
@@ -978,10 +978,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
}
}
- @Override
- public void postProcessParameter(CodegenParameter parameter) {
- }
-
@Override
public Map postProcessModels(Map objs) {
// recursively add import for mapping one type to multiple imports
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java
index 90647b83299..94332fed9d8 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java
@@ -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 postProcessOperationsWithModels(Map operations, List allModels) {
+ Map objs = (Map) operations.get("operations");
+
+ List ops = (List) 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
diff --git a/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache b/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache
index 956b834c88c..95070ee3e73 100644
--- a/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache
+++ b/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache
@@ -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)
}
}
diff --git a/modules/openapi-generator/src/main/resources/Groovy/README.mustache b/modules/openapi-generator/src/main/resources/Groovy/README.mustache
new file mode 100644
index 00000000000..110389077c5
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/Groovy/README.mustache
@@ -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}}
diff --git a/modules/openapi-generator/src/main/resources/Groovy/api.mustache b/modules/openapi-generator/src/main/resources/Groovy/api.mustache
index d20f050432a..20fe23f9623 100644
--- a/modules/openapi-generator/src/main/resources/Groovy/api.mustache
+++ b/modules/openapi-generator/src/main/resources/Groovy/api.mustache
@@ -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}})
diff --git a/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache
index ee7f2e16a7b..b7423c1ef35 100644
--- a/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache
+++ b/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache
@@ -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' }
diff --git a/modules/openapi-generator/src/main/resources/Groovy/model.mustache b/modules/openapi-generator/src/main/resources/Groovy/model.mustache
index 07c0405c98c..e1821824d79 100644
--- a/modules/openapi-generator/src/main/resources/Groovy/model.mustache
+++ b/modules/openapi-generator/src/main/resources/Groovy/model.mustache
@@ -10,11 +10,8 @@ import {{import}};
@Canonical
class {{classname}} {
{{#vars}}
- {{#description}}
- /* {{{description}}} */
- {{/description}}
+ {{#description}}/* {{{description}}} */{{/description}}
{{{dataType}}} {{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
-
{{/vars}}
}
{{/model}}
diff --git a/pom.xml b/pom.xml
index ab648268ec2..46522a7a7a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1019,7 +1019,6 @@
samples/client/petstore/dart-jaguar/flutter_petstore/openapi -->
samples/client/petstore/elm-0.18
- samples/client/petstore/groovy
samples/client/petstore/rust
samples/client/petstore/rust-reqwest
@@ -1096,6 +1095,7 @@
samples/client/petstore/java/resteasy
samples/client/petstore/java/google-api-client
samples/client/petstore/java/rest-assured
+ samples/client/petstore/groovy
samples/server/petstore/jaxrs-jersey
samples/server/petstore/jaxrs-spec
@@ -1176,7 +1176,6 @@
samples/client/petstore/java/vertx
samples/client/petstore/java/resteasy
samples/client/petstore/java/google-api-client
-
samples/server/petstore/jaxrs-jersey
samples/server/petstore/jaxrs-spec
@@ -1222,6 +1221,9 @@
samples/client/petstore/elixir
samples/client/petstore/erlang-client
samples/client/petstore/erlang-proper
+ samples/client/petstore/kotlin/
+ samples/client/petstore/kotlin-threetenbp/
+ samples/client/petstore/kotlin-string/
samples/server/petstore/erlang-server
samples/server/petstore/jaxrs/jersey2
@@ -1229,9 +1231,6 @@
samples/server/petstore/spring-mvc
samples/server/petstore/spring-mvc-j8-async
samples/server/petstore/spring-mvc-j8-localdatetime
- samples/client/petstore/kotlin/
- samples/client/petstore/kotlin-threetenbp/
- samples/client/petstore/kotlin-string/
diff --git a/samples/client/petstore/groovy/README.md b/samples/client/petstore/groovy/README.md
new file mode 100644
index 00000000000..9a975239181
--- /dev/null
+++ b/samples/client/petstore/groovy/README.md
@@ -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}"
+};
+```
+
diff --git a/samples/client/petstore/groovy/build.gradle b/samples/client/petstore/groovy/build.gradle
index 30b440b4dd4..ce8d213336a 100644
--- a/samples/client/petstore/groovy/build.gradle
+++ b/samples/client/petstore/groovy/build.gradle
@@ -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' }
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy
index 0e3473e879f..c1fe94b1027 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/ApiUtils.groovy
@@ -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)
}
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/PetApi.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/PetApi.groovy
index 4dd50a1b29f..c022982020a 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/PetApi.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/PetApi.groovy
@@ -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 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 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 )
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/StoreApi.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/StoreApi.groovy
index 0650a7232b1..154551d1880 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/StoreApi.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/StoreApi.groovy
@@ -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 )
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/UserApi.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/UserApi.groovy
index 0c768494640..2d0ec2ab73c 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/UserApi.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/api/UserApi.groovy
@@ -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 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 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 )
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Category.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Category.groovy
index 305a861bd28..d8ccf48a82a 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Category.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Category.groovy
@@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical
class Category {
+
Long id
-
+
String name
-
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/ModelApiResponse.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/ModelApiResponse.groovy
index 9a1f4fe1680..468841ffff3 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/ModelApiResponse.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/ModelApiResponse.groovy
@@ -6,10 +6,10 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical
class ModelApiResponse {
+
Integer code
-
+
String type
-
+
String message
-
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Order.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Order.groovy
index 6bbffdbd7c9..d9e02f8a6cc 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Order.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Order.groovy
@@ -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
-
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Pet.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Pet.groovy
index eb62fc15ff3..ab4b87def72 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Pet.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Pet.groovy
@@ -10,17 +10,16 @@ import org.openapitools.model.Tag;
@Canonical
class Pet {
+
Long id
-
+
Category category = null
-
+
String name
-
+
List photoUrls = new ArrayList()
-
+
List tags = new ArrayList()
-
/* pet status in the store */
String status
-
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Tag.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Tag.groovy
index 64f08ade6a4..a704bc5ffef 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Tag.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/Tag.groovy
@@ -6,8 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
@Canonical
class Tag {
+
Long id
-
+
String name
-
}
diff --git a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/User.groovy b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/User.groovy
index ed6ebe83392..a6f850e8754 100644
--- a/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/User.groovy
+++ b/samples/client/petstore/groovy/src/main/groovy/org/openapitools/model/User.groovy
@@ -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
-
}
diff --git a/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy b/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy
new file mode 100644
index 00000000000..d62103e4cab
--- /dev/null
+++ b/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy
@@ -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)
+ };
+
+ }
+
+}