mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 15:10:49 +00:00
rollback grovvy template
This commit is contained in:
parent
46c5b776ed
commit
900f39686d
@ -8,43 +8,43 @@ import static java.net.URI.create;
|
|||||||
|
|
||||||
class ApiUtils {
|
class ApiUtils {
|
||||||
|
|
||||||
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, method, container, type) {
|
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, 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 = new HTTPBuilder(url)
|
||||||
http.request( Method.valueOf(method), JSON ) {
|
http.request( Method.valueOf(method), JSON ) {
|
||||||
uri.path = uriPath
|
uri.path = uriPath
|
||||||
uri.query = queryParams
|
uri.query = queryParams
|
||||||
response.success = { resp, json ->
|
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.status, resp.statusLine.reasonPhrase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
// we use java.net.URI to manipulate the basePath
|
// we use java.net.URI to manipulate the basePath
|
||||||
// then the uriPath will hold the rest of the path
|
// then the uriPath will hold the rest of the path
|
||||||
URI baseUri = create(basePath)
|
URI baseUri = create(basePath)
|
||||||
def pathOnly = baseUri.getPath()
|
def pathOnly = baseUri.getPath()
|
||||||
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parse(object, container, clazz) {
|
def parse(object, container, clazz) {
|
||||||
if (container == "List") {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package {{package}};
|
package {{package}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import groovyx.net.http.*
|
import groovyx.net.http.*
|
||||||
import static groovyx.net.http.ContentType.*
|
import static groovyx.net.http.ContentType.*
|
||||||
import static groovyx.net.http.Method.*
|
import static groovyx.net.http.Method.*
|
||||||
@ -14,40 +17,40 @@ import java.util.*;
|
|||||||
|
|
||||||
@Mixin(ApiUtils)
|
@Mixin(ApiUtils)
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
class {{classname}} {
|
class {{classname}} {
|
||||||
String basePath = "{{basePath}}"
|
String basePath = "{{basePath}}"
|
||||||
String versionPath = "/api/v1"
|
String versionPath = "/api/v1"
|
||||||
|
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
String resourcePath = "{{path}}"
|
String resourcePath = "{{path}}"
|
||||||
|
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
def queryParams = [:]
|
def queryParams = [:]
|
||||||
def headerParams = [:]
|
def headerParams = [:]
|
||||||
|
|
||||||
{{#requiredParamCount}}
|
{{#requiredParamCount}}
|
||||||
// verify required params are set
|
// verify required params are set
|
||||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||||
throw new RuntimeException("missing required params")
|
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}}
|
||||||
|
|
||||||
|
{{#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}}
|
{{/operations}}
|
@ -6,24 +6,24 @@ archivesBaseName = 'swagger-gen-groovy'
|
|||||||
version = '0.1'
|
version = '0.1'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' }
|
maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16')
|
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
||||||
maven { url "http://$artifactory:8080/artifactory/repo" }
|
maven { url "http://$artifactory:8080/artifactory/repo" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
groovy "org.codehaus.groovy:groovy-all:2.0.5"
|
groovy "org.codehaus.groovy:groovy-all:2.0.5"
|
||||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
|
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,18 @@ import groovy.transform.Canonical
|
|||||||
{{#imports}}import {{import}};
|
{{#imports}}import {{import}};
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
@Canonical
|
@Canonical
|
||||||
class {{classname}} {
|
class {{classname}} {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
|
||||||
{{#description}}/* {{{description}}} */
|
{{#description}}/* {{{description}}} */
|
||||||
{{/description}}
|
{{/description}}
|
||||||
{{{datatype}}} {{name}} = {{{defaultValue}}}
|
{{{datatype}}} {{name}} = {{{defaultValue}}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
{{/model}}
|
||||||
|
|
||||||
{{/model}}
|
|
||||||
{{/models}}
|
{{/models}}
|
Loading…
x
Reference in New Issue
Block a user