From c3fa24709ffc9b22806a5012ae872c75ce73a1da Mon Sep 17 00:00:00 2001 From: Kengo Seki Date: Fri, 6 Feb 2026 08:43:10 +0900 Subject: [PATCH] [BUG] [Groovy] Fix client to work with services that support other formats in addition to JSON --- bin/configs/groovy.yaml | 1 + .../main/resources/Groovy/ApiUtils.mustache | 64 +++++++++++++++---- .../src/main/resources/Groovy/api.mustache | 5 +- .../resources/Groovy/build.gradle.mustache | 2 + .../src/main/resources/Groovy/model.mustache | 3 + .../main/resources/Groovy/modelClass.mustache | 9 +++ .../main/resources/Groovy/modelEnum.mustache | 6 ++ samples/client/petstore/groovy/build.gradle | 2 + .../org/openapitools/api/ApiUtils.groovy | 33 ++++++---- .../groovy/org/openapitools/api/PetApi.groovy | 40 +++++++++--- .../org/openapitools/api/StoreApi.groovy | 20 ++++-- .../org/openapitools/api/UserApi.groovy | 40 +++++++++--- .../org/openapitools/model/Order.groovy | 6 +- .../groovy/org/openapitools/model/Pet.groovy | 6 +- .../groovy/openapitools/PetApiTest.groovy | 47 +++++++------- 15 files changed, 209 insertions(+), 75 deletions(-) diff --git a/bin/configs/groovy.yaml b/bin/configs/groovy.yaml index a8e13b3cc85e..3d3a9ba28986 100644 --- a/bin/configs/groovy.yaml +++ b/bin/configs/groovy.yaml @@ -3,4 +3,5 @@ outputDir: samples/client/petstore/groovy inputSpec: modules/openapi-generator/src/test/resources/3_0/groovy/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/Groovy additionalProperties: + enumPropertyNaming: "original" hideGenerationTimestamp: "true" diff --git a/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache b/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache index 3acb16972e2f..694b8e9cd522 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/ApiUtils.mustache @@ -1,10 +1,15 @@ package {{invokerPackage}} +{{#withXml}} +import java.io.StringReader +import {{javaxPackage}}.xml.bind.JAXB +{{/withXml}} import groovy.json.JsonBuilder import groovy.json.JsonGenerator import groovyx.net.http.ChainedHttpConfig import groovyx.net.http.ContentTypes import groovyx.net.http.NativeHandlers +import groovyx.net.http.FromServer import groovyx.net.http.ToServer import static groovyx.net.http.HttpBuilder.configure @@ -18,24 +23,42 @@ class ApiUtils { } .build() - void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, method, container, type) { + void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, method, container, type) { def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath) println "url=$url uriPath=$uriPath" def http = configure { request.uri = url request.uri.path = uriPath request.encoder(ContentTypes.JSON, { final ChainedHttpConfig config, final ToServer ts -> - final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); + final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest() if (NativeHandlers.Encoders.handleRawUpload(config, ts)) { - return; + return } - final Object body = NativeHandlers.Encoders.checkNull(request.actualBody()); + final Object body = NativeHandlers.Encoders.checkNull(request.actualBody()) final String json = ((body instanceof String || body instanceof GString) ? body.toString() - : new JsonBuilder(body, jsonGenerator).toString()); - ts.toServer(NativeHandlers.Encoders.stringToStream(json, request.actualCharset())); + : new JsonBuilder(body, jsonGenerator).toString()) + ts.toServer(NativeHandlers.Encoders.stringToStream(json, request.actualCharset())) }) + {{#withXml}} + request.encoder(ContentTypes.XML, { final ChainedHttpConfig config, final ToServer ts -> + final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest() + if (NativeHandlers.Encoders.handleRawUpload(config, ts)) { + return + } + + final Object body = NativeHandlers.Encoders.checkNull(request.actualBody()) + String xml + if (body instanceof String || body instanceof GString) { + xml = body.toString() + } else { + StringWriter writer = new StringWriter() + JAXB.marshal(body, writer) + xml = writer.toString() + } + ts.toServer(NativeHandlers.Encoders.stringToStream(xml, request.actualCharset())) + }){{/withXml}} } .invokeMethod(String.valueOf(method).toLowerCase()) { request.uri.query = queryParams @@ -43,11 +66,16 @@ class ApiUtils { if (bodyParams != null) { request.body = bodyParams } + request.accept = accept request.contentType = contentType - - response.success { resp, json -> + {{#withXml}} + response.parser(ContentTypes.XML) { final ChainedHttpConfig cfg, final FromServer fs -> + fs.inputStream.text + } + {{/withXml}} + response.success { resp, body -> if (type != null) { - onSuccess(parse(json, container, type)) + onSuccess(parse(resp, body, container, type)) } } response.failure { resp -> @@ -68,12 +96,24 @@ class ApiUtils { [basePath-pathOnly, pathOnly+versionPath+resourcePath] } - private def parse(object, container, clazz) { + private def parse(response, object, container, clazz) { + {{#withXml}} + if (response.getContentType().toLowerCase().contains("xml")) { + return JAXB.unmarshal(new StringReader(object), clazz) + } + {{/withXml}} if (container == "array") { - return object.collect {parse(it, "", clazz)} - } else { + return object.collect { parse(response, it, "", clazz) } + } else { return clazz.newInstance(object) } } + private def selectHeaderAccept(accepts) { + def jsonMime = 'application/json' + if (accepts.find { it.toLowerCase().startsWith(jsonMime) }) { + return [jsonMime] + } + return accepts + } } diff --git a/modules/openapi-generator/src/main/resources/Groovy/api.mustache b/modules/openapi-generator/src/main/resources/Groovy/api.mustache index a7ee609852e1..2b5fde13969f 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/api.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/api.mustache @@ -18,6 +18,7 @@ class {{classname}} { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType {{#allParams}} @@ -71,7 +72,9 @@ class {{classname}} { {{/formParams}} {{/hasFormParams}} - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "{{httpMethod}}", "{{returnContainer}}", {{#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 f29780b19bd1..3c0aad05e0b6 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/build.gradle.mustache @@ -1,6 +1,7 @@ apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.github.johnrengelman.shadow' group = '{{groupId}}' version = '{{artifactVersion}}' @@ -18,6 +19,7 @@ buildscript { } dependencies { classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.24.20') + classpath('com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:4.0.4') } } diff --git a/modules/openapi-generator/src/main/resources/Groovy/model.mustache b/modules/openapi-generator/src/main/resources/Groovy/model.mustache index 1c304c98d920..ccb5430d816a 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/model.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/model.mustache @@ -4,6 +4,9 @@ import groovy.transform.Canonical {{#imports}} import {{import}}; {{/imports}} +{{#withXml}} +import {{javaxPackage}}.xml.bind.annotation.*; +{{/withXml}} {{#models}} {{#model}} diff --git a/modules/openapi-generator/src/main/resources/Groovy/modelClass.mustache b/modules/openapi-generator/src/main/resources/Groovy/modelClass.mustache index 39c0c6aa3844..6c9a78a23afa 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/modelClass.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/modelClass.mustache @@ -1,3 +1,6 @@ +{{#withXml}} +@XmlAccessorType(XmlAccessType.NONE) +{{/withXml}} @Canonical class {{classname}} { {{#vars}} @@ -16,6 +19,12 @@ class {{classname}} { {{/isEnum}} {{#description}}/* {{{.}}} */{{/description}} + {{#withXml}} + @Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) + {{#isXmlWrapped}} + @XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) + {{/isXmlWrapped}} + {{/withXml}} {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}} {{/vars}} } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache b/modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache index 493be4503d15..b2df92db4e75 100644 --- a/modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/Groovy/modelEnum.mustache @@ -1,3 +1,6 @@ +{{#withXml}} +@XmlEnum +{{/withXml}} enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { {{#allowableValues}}{{#enumVars}} {{#enumDescription}} @@ -5,6 +8,9 @@ enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEn * {{.}} */ {{/enumDescription}} + {{#withXml}} + @XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) + {{/withXml}} {{{name}}}({{{value}}}){{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} diff --git a/samples/client/petstore/groovy/build.gradle b/samples/client/petstore/groovy/build.gradle index 28c8b726cd8c..394221252e72 100644 --- a/samples/client/petstore/groovy/build.gradle +++ b/samples/client/petstore/groovy/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.github.johnrengelman.shadow' group = 'org.openapitools' version = '1.0.0' @@ -18,6 +19,7 @@ buildscript { } dependencies { classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.24.20') + classpath('com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:4.0.4') } } 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 cc4d3d248e5a..52041003fd9d 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 @@ -5,6 +5,7 @@ import groovy.json.JsonGenerator import groovyx.net.http.ChainedHttpConfig import groovyx.net.http.ContentTypes import groovyx.net.http.NativeHandlers +import groovyx.net.http.FromServer import groovyx.net.http.ToServer import static groovyx.net.http.HttpBuilder.configure @@ -18,24 +19,25 @@ class ApiUtils { } .build() - void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, method, container, type) { + void invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, method, container, type) { def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath) println "url=$url uriPath=$uriPath" def http = configure { request.uri = url request.uri.path = uriPath request.encoder(ContentTypes.JSON, { final ChainedHttpConfig config, final ToServer ts -> - final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest(); + final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest() if (NativeHandlers.Encoders.handleRawUpload(config, ts)) { - return; + return } - final Object body = NativeHandlers.Encoders.checkNull(request.actualBody()); + final Object body = NativeHandlers.Encoders.checkNull(request.actualBody()) final String json = ((body instanceof String || body instanceof GString) ? body.toString() - : new JsonBuilder(body, jsonGenerator).toString()); - ts.toServer(NativeHandlers.Encoders.stringToStream(json, request.actualCharset())); + : new JsonBuilder(body, jsonGenerator).toString()) + ts.toServer(NativeHandlers.Encoders.stringToStream(json, request.actualCharset())) }) + } .invokeMethod(String.valueOf(method).toLowerCase()) { request.uri.query = queryParams @@ -43,11 +45,11 @@ class ApiUtils { if (bodyParams != null) { request.body = bodyParams } + request.accept = accept request.contentType = contentType - - response.success { resp, json -> + response.success { resp, body -> if (type != null) { - onSuccess(parse(json, container, type)) + onSuccess(parse(resp, body, container, type)) } } response.failure { resp -> @@ -68,12 +70,19 @@ class ApiUtils { [basePath-pathOnly, pathOnly+versionPath+resourcePath] } - private def parse(object, container, clazz) { + private def parse(response, object, container, clazz) { if (container == "array") { - return object.collect {parse(it, "", clazz)} - } else { + return object.collect { parse(response, it, "", clazz) } + } else { return clazz.newInstance(object) } } + private def selectHeaderAccept(accepts) { + def jsonMime = 'application/json' + if (accepts.find { it.toLowerCase().startsWith(jsonMime) }) { + return [jsonMime] + } + return accepts + } } 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 a9f63306dcb5..fca310942b53 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 @@ -16,6 +16,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -29,7 +30,9 @@ class PetApi { bodyParams = pet - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "POST", "", Pet.class ) @@ -42,6 +45,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -56,7 +60,9 @@ class PetApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "DELETE", "", null ) @@ -69,6 +75,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -83,7 +90,9 @@ class PetApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "array", Pet.class ) @@ -96,6 +105,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -110,7 +120,9 @@ class PetApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "array", Pet.class ) @@ -123,6 +135,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -134,7 +147,9 @@ class PetApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "", Pet.class ) @@ -147,6 +162,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -160,7 +176,9 @@ class PetApi { bodyParams = pet - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "PUT", "", Pet.class ) @@ -173,6 +191,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -188,7 +207,9 @@ class PetApi { bodyParams.put("name", name) bodyParams.put("status", status) - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "POST", "", null ) @@ -201,6 +222,7 @@ class PetApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -216,7 +238,9 @@ class PetApi { bodyParams.put("additionalMetadata", additionalMetadata) bodyParams.put("file", _file) - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, 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 b61c6992fb17..f10e6da7136a 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 @@ -15,6 +15,7 @@ class StoreApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -26,7 +27,9 @@ class StoreApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "DELETE", "", null ) @@ -39,6 +42,7 @@ class StoreApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType @@ -46,7 +50,9 @@ class StoreApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "map", Integer.class ) @@ -59,6 +65,7 @@ class StoreApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -70,7 +77,9 @@ class StoreApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "", Order.class ) @@ -83,6 +92,7 @@ class StoreApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -96,7 +106,9 @@ class StoreApi { bodyParams = order - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, 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 579563fb85d7..7750849973c8 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 @@ -15,6 +15,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -28,7 +29,9 @@ class UserApi { bodyParams = user - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "POST", "", null ) @@ -41,6 +44,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -54,7 +58,9 @@ class UserApi { bodyParams = user - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "POST", "", null ) @@ -67,6 +73,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -80,7 +87,9 @@ class UserApi { bodyParams = user - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "POST", "", null ) @@ -93,6 +102,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -104,7 +114,9 @@ class UserApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "DELETE", "", null ) @@ -117,6 +129,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -128,7 +141,9 @@ class UserApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "", User.class ) @@ -141,6 +156,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -162,7 +178,9 @@ class UserApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept(["application/xml", "application/json"]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "", String.class ) @@ -175,6 +193,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType @@ -182,7 +201,9 @@ class UserApi { - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "GET", "", null ) @@ -195,6 +216,7 @@ class UserApi { def queryParams = [:] def headerParams = [:] def bodyParams + def accept def contentType // verify required params are set @@ -212,7 +234,9 @@ class UserApi { bodyParams = user - apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, contentType, + accept = apiUtils.selectHeaderAccept([]) + + apiUtils.invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, bodyParams, accept, contentType, "PUT", "", null ) 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 fb00b075b844..fc443804a7ba 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 @@ -17,11 +17,11 @@ class Order { enum StatusEnum { - PLACED("placed"), + placed("placed"), - APPROVED("approved"), + approved("approved"), - DELIVERED("delivered") + delivered("delivered") private final String value 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 1ca93fb46c9e..2f463b588603 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 @@ -23,11 +23,11 @@ class Pet { enum StatusEnum { - AVAILABLE("available"), + available("available"), - PENDING("pending"), + pending("pending"), - SOLD("sold") + sold("sold") private final String value diff --git a/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy b/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy index fb8028800adf..de15f318ebc3 100644 --- a/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy +++ b/samples/client/petstore/groovy/src/test/groovy/openapitools/PetApiTest.groovy @@ -49,7 +49,7 @@ class PetApiTest extends GroovyTestCase { def pet = new Pet() pet.setId(this.petId) pet.setName("groovy client updatetest") - //pet.setStatus("pending") + pet.setStatus(Pet.StatusEnum.pending) this.petApi.updatePet(pet) { } { @@ -61,7 +61,7 @@ class PetApiTest extends GroovyTestCase { def petGetted = (Pet)it assertEquals(this.petId, petGetted.getId()) assertEquals("groovy client updatetest", petGetted.getName()) - //assertEquals("pending", petGetted.getStatus()) + assertEquals(Pet.StatusEnum.pending, petGetted.getStatus()) } { statusCode, message -> @@ -75,16 +75,16 @@ class PetApiTest extends GroovyTestCase { 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.getPetById(this.petId) { + def petGetted = (Pet)it + assertEquals(this.petId, petGetted.getId()) + assertEquals("groovy client updatetestwithform", petGetted.getName()) + assertEquals(Pet.StatusEnum.sold, petGetted.getStatus()) + } + { + statusCode, message -> + assertEquals(200, statusCode) + }; this.petApi.deletePet(this.petId, "apiKey") { } @@ -104,17 +104,16 @@ class PetApiTest extends GroovyTestCase { } - //@Ignore("due to illegal argument exception in findPetByStatus") - //@Test - //void testGetPetByStatus() { - // this.petApi.findPetsByStatus(["sold"]) { - // def listPets = (ArrayList)it - // assertTrue(listPets.size() > 0) - // } - // { - // statusCode, message -> - // assertEquals(200, statusCode) - // }; - //} + @Test + void testGetPetByStatus() { + this.petApi.findPetsByStatus(["sold"]) { + def listPets = (ArrayList)it + assertTrue(listPets.size() > 0) + } + { + statusCode, message -> + assertEquals(200, statusCode) + }; + } }