Update Groovy petstore client via OAS2 (#133)

* restore groovy client from codegen 2x

* update groovy client with oas2

* reformat groovy templates to remove empty lines
This commit is contained in:
William Cheng
2018-04-23 14:12:37 +08:00
committed by GitHub
parent a2e299fe1a
commit 2833319b81
13 changed files with 136 additions and 161 deletions

View File

@@ -24,31 +24,33 @@ class {{classname}} {
// query params
def queryParams = [:]
def headerParams = [:]
{{#allParams}}
{{#required}}
// verify required params are set
if ({{paramName}} == null) {
throw new RuntimeException("missing required params {{paramName}}")
}
{{/required}}
{{/allParams}}
{{#queryParams}}if (!"null".equals(String.valueOf({{paramName}})))
{{#queryParams}}
if (!"null".equals(String.valueOf({{paramName}})))
queryParams.put("{{baseName}}", String.valueOf({{paramName}}))
{{/queryParams}}
{{/queryParams}}
{{#headerParams}}
headerParams.put("{{baseName}}", {{paramName}})
{{/headerParams}}
// Also still TODO: form params, body param
{{/headerParams}}
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"{{httpMethod}}", "{{returnContainer}}",
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
}
{{/operation}}
}
{{/operations}}

View File

@@ -1,21 +1,21 @@
package {{package}};
import groovy.transform.Canonical
{{#imports}}import {{import}};
{{#imports}}
import {{import}};
{{/imports}}
{{#models}}
{{#model}}
@Canonical
class {{classname}} {
{{#vars}}
{{#description}}/* {{{description}}} */
{{/description}}
{{{datatype}}} {{name}} = {{{defaultValue}}}
{{/vars}}
{{#vars}}
{{#description}}
/* {{{description}}} */
{{/description}}
{{{datatype}}} {{name}} = {{{defaultValue}}}
{{/vars}}
}
{{/model}}
{{/models}}

View File

@@ -1 +1 @@
2.4.0-SNAPSHOT
3.0.0-SNAPSHOT

View File

@@ -16,28 +16,27 @@ class PetApi {
String basePath = "http://petstore.swagger.io/v2"
String versionPath = "/api/v1"
def addPet ( Pet body, Closure onSuccess, Closure onFailure) {
def addPet ( Pet pet, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (pet == null) {
throw new RuntimeException("missing required params pet")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def deletePet ( Long petId, String apiKey, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/{petId}"
@@ -45,22 +44,22 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (petId == null) {
throw new RuntimeException("missing required params petId")
}
headerParams.put("api_key", apiKey)
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def findPetsByStatus ( List<String> status, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/findByStatus"
@@ -68,7 +67,7 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (status == null) {
throw new RuntimeException("missing required params status")
@@ -77,14 +76,14 @@ class PetApi {
if (!"null".equals(String.valueOf(status)))
queryParams.put("status", String.valueOf(status))
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "array",
Pet.class )
}
def findPetsByTags ( List<String> tags, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/findByTags"
@@ -92,7 +91,7 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (tags == null) {
throw new RuntimeException("missing required params tags")
@@ -101,14 +100,14 @@ class PetApi {
if (!"null".equals(String.valueOf(tags)))
queryParams.put("tags", String.valueOf(tags))
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "array",
Pet.class )
}
def getPetById ( Long petId, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet/{petId}"
@@ -116,43 +115,41 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (petId == null) {
throw new RuntimeException("missing required params petId")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
Pet.class )
}
def updatePet ( Pet body, Closure onSuccess, Closure onFailure) {
def updatePet ( Pet pet, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/pet"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (pet == null) {
throw new RuntimeException("missing required params pet")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
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 path parameters (TODO)
String resourcePath = "/pet/{petId}"
@@ -160,21 +157,20 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (petId == null) {
throw new RuntimeException("missing required params petId")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
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 path parameters (TODO)
String resourcePath = "/pet/{petId}/uploadImage"
@@ -182,19 +178,18 @@ class PetApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (petId == null) {
throw new RuntimeException("missing required params petId")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
ModelApiResponse.class )
}
}

View File

@@ -22,21 +22,20 @@ class StoreApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (orderId == null) {
throw new RuntimeException("missing required params orderId")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def getInventory ( Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/store/inventory"
@@ -44,17 +43,15 @@ class StoreApi {
// query params
def queryParams = [:]
def headerParams = [:]
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "map",
Map.class )
Integer.class )
}
def getOrderById ( Long orderId, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/store/order/{orderId}"
@@ -62,41 +59,39 @@ class StoreApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (orderId == null) {
throw new RuntimeException("missing required params orderId")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
Order.class )
}
def placeOrder ( Order body, Closure onSuccess, Closure onFailure) {
def placeOrder ( Order order, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/store/order"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (order == null) {
throw new RuntimeException("missing required params order")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
Order.class )
}
}

View File

@@ -14,72 +14,69 @@ class UserApi {
String basePath = "http://petstore.swagger.io/v2"
String versionPath = "/api/v1"
def createUser ( User body, Closure onSuccess, Closure onFailure) {
def createUser ( User user, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (user == null) {
throw new RuntimeException("missing required params user")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def createUsersWithArrayInput ( List<User> body, Closure onSuccess, Closure onFailure) {
def createUsersWithArrayInput ( List<User> user, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/createWithArray"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (user == null) {
throw new RuntimeException("missing required params user")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def createUsersWithListInput ( List<User> body, Closure onSuccess, Closure onFailure) {
def createUsersWithListInput ( List<User> user, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/createWithList"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (user == null) {
throw new RuntimeException("missing required params user")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"POST", "",
null )
}
def deleteUser ( String username, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/{username}"
@@ -87,21 +84,20 @@ class UserApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (username == null) {
throw new RuntimeException("missing required params username")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"DELETE", "",
null )
}
def getUserByName ( String username, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/{username}"
@@ -109,21 +105,20 @@ class UserApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (username == null) {
throw new RuntimeException("missing required params username")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
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 path parameters (TODO)
String resourcePath = "/user/login"
@@ -131,11 +126,12 @@ class UserApi {
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (username == null) {
throw new RuntimeException("missing required params username")
}
// verify required params are set
if (password == null) {
throw new RuntimeException("missing required params password")
@@ -143,17 +139,18 @@ class UserApi {
if (!"null".equals(String.valueOf(username)))
queryParams.put("username", String.valueOf(username))
if (!"null".equals(String.valueOf(password)))
if (!"null".equals(String.valueOf(password)))
queryParams.put("password", String.valueOf(password))
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
String.class )
}
def logoutUser ( Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/logout"
@@ -161,41 +158,39 @@ if (!"null".equals(String.valueOf(password)))
// query params
def queryParams = [:]
def headerParams = [:]
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"GET", "",
null )
}
def updateUser ( String username, User body, Closure onSuccess, Closure onFailure) {
def updateUser ( String username, User user, Closure onSuccess, Closure onFailure) {
// create path and map path parameters (TODO)
String resourcePath = "/user/{username}"
// query params
def queryParams = [:]
def headerParams = [:]
// verify required params are set
if (username == null) {
throw new RuntimeException("missing required params username")
}
// verify required params are set
if (body == null) {
throw new RuntimeException("missing required params body")
if (user == null) {
throw new RuntimeException("missing required params user")
}
// Also still TODO: form params, body param
// TODO: form params, body param not yet support
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
"PUT", "",
null )
}
}

View File

@@ -3,13 +3,11 @@ package io.swagger.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class Category {
Long id = null
String name = null
}

View File

@@ -3,15 +3,13 @@ package io.swagger.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class ModelApiResponse {
Integer code = null
String type = null
String message = null
}

View File

@@ -4,9 +4,9 @@ import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.model.Date;
@Canonical
class Order {
Long id = null
Long petId = null
@@ -15,11 +15,9 @@ class Order {
Date shipDate = null
/* Order Status */
String status = null
/* Order Status */
String status = null
Boolean complete = false
}

View File

@@ -7,9 +7,9 @@ import io.swagger.model.ArrayList;
import io.swagger.model.Category;
import io.swagger.model.Tag;
import java.util.List;
@Canonical
class Pet {
Long id = null
Category category = null
@@ -20,9 +20,7 @@ class Pet {
List<Tag> tags = new ArrayList<Tag>()
/* pet status in the store */
String status = null
/* pet status in the store */
String status = null
}

View File

@@ -3,13 +3,11 @@ package io.swagger.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class Tag {
Long id = null
String name = null
}

View File

@@ -3,9 +3,9 @@ package io.swagger.model;
import groovy.transform.Canonical
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Canonical
class User {
Long id = null
String username = null
@@ -20,9 +20,7 @@ class User {
String phone = null
/* User Status */
Integer userStatus = null
/* User Status */
Integer userStatus = null
}