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 {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package {{package}};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
@ -14,7 +17,7 @@ import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
{{#operations}}
|
||||
class {{classname}} {
|
||||
class {{classname}} {
|
||||
String basePath = "{{basePath}}"
|
||||
String versionPath = "/api/v1"
|
||||
|
||||
@ -49,5 +52,5 @@ import java.util.*;
|
||||
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
}
|
||||
{{/operations}}
|
@ -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'
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import groovy.transform.Canonical
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
@Canonical
|
||||
class {{classname}} {
|
||||
{{#model}}
|
||||
@Canonical
|
||||
class {{classname}} {
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}/* {{{description}}} */
|
||||
@ -15,7 +15,7 @@ import groovy.transform.Canonical
|
||||
{{/vars}}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{{/model}}
|
||||
{{/model}}
|
||||
{{/models}}
|
Loading…
x
Reference in New Issue
Block a user