Update Groovy default value, fix import error when doing "gradle test" (#203)

* update groovy default value, fix import error when doing gradle test

* remove empty lines
This commit is contained in:
William Cheng 2018-04-23 17:31:14 +08:00 committed by GitHub
parent 16589de975
commit b908b734dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 35 additions and 742 deletions

3
.gitignore vendored
View File

@ -188,3 +188,6 @@ cabal.project.local
samples/client/petstore/elixir/_build/
samples/client/petstore/elixir/deps/
samples/client/petstore/elixir/mix.lock
# groovy
samples/client/petstore/groovy/build

View File

@ -12,9 +12,11 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
public GroovyClientCodegen() {
super();
// clear import mapping (from default generator) as groovy does not use it
// at the moment
importMapping.clear();
// avoid importing the following as models
languageSpecificPrimitives.add("Date");
languageSpecificPrimitives.add("ArrayList");
languageSpecificPrimitives.add("File");
languageSpecificPrimitives.add("Map");
sourceFolder = projectFolder + File.separator + "groovy";
outputFolder = "generated-code/groovy";
@ -29,18 +31,17 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
modelDocTemplateFiles.remove("model_doc.mustache");
apiDocTemplateFiles.remove("api_doc.mustache");
apiPackage = "io.swagger.api";
modelPackage = "io.swagger.model";
configPackage = "io.swagger.configuration";
invokerPackage = "io.swagger.api";
artifactId = "swagger-groovy";
apiPackage = "org.openapitools.api";
modelPackage = "org.openapitools.model";
configPackage = "org.openapitools.configuration";
invokerPackage = "org.openapitools.api";
artifactId = "openapi-groovy";
dateLibrary = "legacy"; //TODO: add joda support to groovy
additionalProperties.put("title", title);
additionalProperties.put(CONFIG_PACKAGE, configPackage);
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
}
@Override

View File

@ -18,4 +18,4 @@ class {{classname}} {
{{/vars}}
}
{{/model}}
{{/models}}
{{/models}}

View File

@ -1 +1 @@
2.2.3-SNAPSHOT
3.0.0-SNAPSHOT

View File

@ -1,4 +1,4 @@
package io.swagger.api;
package org.openapitools.api;
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

View File

@ -1,13 +1,12 @@
package io.swagger.api;
package org.openapitools.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
import org.openapitools.api.ApiUtils
import io.swagger.model.File
import io.swagger.model.ModelApiResponse
import io.swagger.model.Pet
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import java.util.*;

View File

@ -1,12 +1,11 @@
package io.swagger.api;
package org.openapitools.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
import org.openapitools.api.ApiUtils
import io.swagger.model.Map
import io.swagger.model.Order
import org.openapitools.model.Order
import java.util.*;

View File

@ -1,11 +1,11 @@
package io.swagger.api;
package org.openapitools.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
import org.openapitools.api.ApiUtils
import io.swagger.model.User
import org.openapitools.model.User
import java.util.*;

View File

@ -1,4 +1,4 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;

View File

@ -1,9 +1,8 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.model.Date;
@Canonical
class Order {

View File

@ -1,12 +1,12 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.model.ArrayList;
import io.swagger.model.Category;
import io.swagger.model.Tag;
import java.util.ArrayList;
import java.util.List;
import org.openapitools.model.Category;
import org.openapitools.model.Tag;
@Canonical
class Pet {

View File

@ -1,4 +1,4 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package io.swagger.model;
package org.openapitools.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;

View File

@ -1,50 +0,0 @@
package io.swagger.api;
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import static groovyx.net.http.ContentType.JSON
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 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)
}
}
}

View File

@ -1,218 +0,0 @@
package io.swagger.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
//-------------
import io.swagger.model.Pet
import java.io.File
import io.swagger.model.ModelApiResponse
import java.util.*;
@Mixin(ApiUtils)
class PetApi {
String basePath = "http://petstore.swagger.io/v2"
String versionPath = "/api/v1"
def addPet ( Pet body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = ""
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def deletePet ( Long petId, String apiKey, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{petId}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if( // verify required params are set
if() {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
headerParams.put("apiKey", apiKey)
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def findPetsByStatus ( List<String> status, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/findByStatus"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
if(!"null".equals(String.valueOf(status)))
queryParams.put("status", String.valueOf(status))
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "List",
Pet.class )
}
def findPetsByTags ( List<String> tags, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/findByTags"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
if(!"null".equals(String.valueOf(tags)))
queryParams.put("tags", String.valueOf(tags))
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "List",
Pet.class )
}
def getPetById ( Long petId, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{petId}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
Pet.class )
}
def updatePet ( Pet body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = ""
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"PUT", "",
null )
}
def updatePetWithForm ( Long petId, String name, String status, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{petId}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if( // verify required params are set
if( // verify required params are set
if() {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def uploadFile ( Long petId, String additionalMetadata, File file, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{petId}/uploadImage"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if( // verify required params are set
if( // verify required params are set
if() {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
ModelApiResponse.class )
}
}

View File

@ -1,104 +0,0 @@
package io.swagger.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
//-------------
import java.util.Map
import io.swagger.model.Order
import java.util.*;
@Mixin(ApiUtils)
class StoreApi {
String basePath = "http://petstore.swagger.io/v2"
String versionPath = "/api/v1"
def deleteOrder ( String orderId, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/order/{orderId}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def getInventory ( Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/inventory"
// query params
def queryParams = [:]
def headerParams = [:]
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "Map",
Map.class )
}
def getOrderById ( Long orderId, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/order/{orderId}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
Order.class )
}
def placeOrder ( Order body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/order"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
Order.class )
}
}

View File

@ -1,200 +0,0 @@
package io.swagger.api;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import io.swagger.api.ApiUtils
//-------------
import io.swagger.model.User
import java.util.List
import java.util.*;
@Mixin(ApiUtils)
class UserApi {
String basePath = "http://petstore.swagger.io/v2"
String versionPath = "/api/v1"
def createUser ( User body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = ""
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def createUsersWithArrayInput ( List<User> body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/createWithArray"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def createUsersWithListInput ( List<User> body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/createWithList"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def deleteUser ( String username, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{username}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def getUserByName ( String username, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{username}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if() {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
User.class )
}
def loginUser ( String username, String password, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/login"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if( // verify required params are set
if() {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
if(!"null".equals(String.valueOf(username)))
queryParams.put("username", String.valueOf(username))
if(!"null".equals(String.valueOf(password)))
queryParams.put("password", String.valueOf(password))
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
String.class )
}
def logoutUser ( Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/logout"
// query params
def queryParams = [:]
def headerParams = [:]
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
null )
}
def updateUser ( String username, User body, Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/{username}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if( // verify required params are set
if() {
throw new RuntimeException("missing required params")
}
) {
throw new RuntimeException("missing required params")
}
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"PUT", "",
null )
}
}

View File

@ -1,16 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class Category {
Long id = null
String name = null
}

View File

@ -1,18 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class ModelApiResponse {
Integer code = null
String type = null
String message = null
}

View File

@ -1,27 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
@Canonical
class Order {
Long id = null
Long petId = null
Integer quantity = null
Date shipDate = null
/* Order Status */
String status = null
Boolean complete = false
}

View File

@ -1,30 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.model.Category;
import io.swagger.model.Tag;
import java.util.ArrayList;
import java.util.List;
@Canonical
class Pet {
Long id = null
Category category = null
String name = null
List<String> photoUrls = new ArrayList<String>()
List<Tag> tags = new ArrayList<Tag>()
/* pet status in the store */
String status = null
}

View File

@ -1,16 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class Tag {
Long id = null
String name = null
}

View File

@ -1,29 +0,0 @@
package io.swagger.model;
import groovy.transform.Canonical
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class User {
Long id = null
String username = null
String firstName = null
String lastName = null
String email = null
String password = null
String phone = null
/* User Status */
Integer userStatus = null
}