diff --git a/modules/swagger-codegen/src/main/resources/Groovy/ApiUtils.mustache b/modules/swagger-codegen/src/main/resources/Groovy/ApiUtils.mustache index 725f7476afc..956b834c88c 100644 --- a/modules/swagger-codegen/src/main/resources/Groovy/ApiUtils.mustache +++ b/modules/swagger-codegen/src/main/resources/Groovy/ApiUtils.mustache @@ -8,43 +8,43 @@ import static java.net.URI.create; class ApiUtils { -def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, 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 -> -if (type != null) { -onSuccess(parse(json, container, type)) -} -} -response.failure = { resp -> -onFailure(resp.status, resp.statusLine.reasonPhrase) -} -} -} + def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, 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 -> + if (type != null) { + onSuccess(parse(json, container, type)) + } + } + response.failure = { resp -> + onFailure(resp.status, resp.statusLine.reasonPhrase) + } + } + } -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 -// we use java.net.URI to manipulate the basePath -// then the uriPath will hold the rest of the path -URI baseUri = create(basePath) -def pathOnly = baseUri.getPath() -[basePath-pathOnly, pathOnly+versionPath+resourcePath] -} + 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 + // we use java.net.URI to manipulate the basePath + // then the uriPath will hold the rest of the path + URI baseUri = create(basePath) + def pathOnly = baseUri.getPath() + [basePath-pathOnly, pathOnly+versionPath+resourcePath] + } -def parse(object, container, clazz) { -if (container == "List") { -return object.collect {parse(it, "", clazz)} -} else { -return clazz.newInstance(object) -} -} + def parse(object, container, clazz) { + if (container == "List") { + return object.collect {parse(it, "", clazz)} + } else { + return clazz.newInstance(object) + } + } } diff --git a/modules/swagger-codegen/src/main/resources/Groovy/api.mustache b/modules/swagger-codegen/src/main/resources/Groovy/api.mustache index 8ab77047d4f..6ff66a84720 100644 --- a/modules/swagger-codegen/src/main/resources/Groovy/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Groovy/api.mustache @@ -1,6 +1,9 @@ package {{package}}; + + + import groovyx.net.http.* import static groovyx.net.http.ContentType.* import static groovyx.net.http.Method.* @@ -14,40 +17,40 @@ import java.util.*; @Mixin(ApiUtils) {{#operations}} - class {{classname}} { +class {{classname}} { String basePath = "{{basePath}}" String versionPath = "/api/v1" - {{#operation}} - def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) { - // create path and map variables - String resourcePath = "{{path}}" + {{#operation}} + def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) { + // create path and map variables + String resourcePath = "{{path}}" - // query params - def queryParams = [:] - def headerParams = [:] + // query params + def queryParams = [:] + def headerParams = [:] - {{#requiredParamCount}} - // verify required params are set - if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) { - throw new RuntimeException("missing required params") - } - {{/requiredParamCount}} - - {{#queryParams}}if(!"null".equals(String.valueOf({{paramName}}))) - queryParams.put("{{paramName}}", String.valueOf({{paramName}})) - {{/queryParams}} - - {{#headerParams}}headerParams.put("{{paramName}}", {{paramName}}) - {{/headerParams}} - - invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, - "{{httpMethod}}", "{{returnContainer}}", - {{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}}) - - } - {{/operation}} + {{#requiredParamCount}} + // verify required params are set + if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) { + throw new RuntimeException("missing required params") } + {{/requiredParamCount}} + + {{#queryParams}}if(!"null".equals(String.valueOf({{paramName}}))) + queryParams.put("{{paramName}}", String.valueOf({{paramName}})) + {{/queryParams}} + + {{#headerParams}}headerParams.put("{{paramName}}", {{paramName}}) + {{/headerParams}} + + invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, + "{{httpMethod}}", "{{returnContainer}}", + {{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}}) + + } + {{/operation}} +} {{/operations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/Groovy/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Groovy/build.gradle.mustache index ed8599e357b..d98f375c61d 100644 --- a/modules/swagger-codegen/src/main/resources/Groovy/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Groovy/build.gradle.mustache @@ -6,24 +6,24 @@ archivesBaseName = 'swagger-gen-groovy' version = '0.1' buildscript { -repositories { -maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' } -} -dependencies { -classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16') -} + repositories { + maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' } + } + dependencies { + classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16') + } } repositories { -mavenCentral() -mavenLocal() -mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone']) -maven { url "http://$artifactory:8080/artifactory/repo" } + mavenCentral() + mavenLocal() + mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone']) + maven { url "http://$artifactory:8080/artifactory/repo" } } dependencies { -groovy "org.codehaus.groovy:groovy-all:2.0.5" -compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' + groovy "org.codehaus.groovy:groovy-all:2.0.5" + compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' } diff --git a/modules/swagger-codegen/src/main/resources/Groovy/model.mustache b/modules/swagger-codegen/src/main/resources/Groovy/model.mustache index 6e4843811b2..bc3ca28aaec 100644 --- a/modules/swagger-codegen/src/main/resources/Groovy/model.mustache +++ b/modules/swagger-codegen/src/main/resources/Groovy/model.mustache @@ -4,18 +4,18 @@ import groovy.transform.Canonical {{#imports}}import {{import}}; {{/imports}} {{#models}} - {{#model}} - @Canonical - class {{classname}} { - {{#vars}} +{{#model}} +@Canonical +class {{classname}} { + {{#vars}} - {{#description}}/* {{{description}}} */ - {{/description}} - {{{datatype}}} {{name}} = {{{defaultValue}}} - {{/vars}} + {{#description}}/* {{{description}}} */ + {{/description}} + {{{datatype}}} {{name}} = {{{defaultValue}}} + {{/vars}} + +} - } - - {{/model}} +{{/model}} {{/models}} \ No newline at end of file