wordnik/swagger-codegen — pull request #73 by victorgit (2013-07-18 11:54:06+00:00)
Title: Code that generates a groovy plugin based on the swagger resources

This is a code that generates groovy client for the APIs.
The basic idea of the groovy client that will be generated is to use 'onSuccess' and 'onFailure' closures that the user will provide when invoking the client code. The generated code will then invoke these closures when relevant.
For build will use gradle and will generate a build.gradle file

* BasicGroovyGenerator - as Groovy is an extension of Java, this generator extends BasicJavaGenerator and modify only relevant implementation parts, such as file extensions, the supporting files to generate etc.
* The resources includes the mustache templates:

1. model.mustache - a template for the model class in Groovy. For example:

import groovy.transform.Canonical
@Canonical
class Car {
String model = null
String year = null
String make = null
}

2. ApiUtils.mustache - the utility class that implements the actual API calls using 'groovyx.net.http.HTTPBuilder'
3. api.mustache - a template for the actual API. The generated code will delegate for ApiUtils.invokeApi(). For example:

@Mixin(ApiUtils)
class CarsApi {
String basePath = "http://localhost:8080/swa"
String versionPath = "/api/v1"

def cars (Closure onSuccess, Closure onFailure) {
// create path and map variables
String resourcePath = "/cars"
// query params
def queryParams = [:]
def headerParams = [:]
if(!"null".equals(String.valueOf(carName)))
queryParams.put("carName", String.valueOf(carName))
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath,
queryParams, headerParams, "GET", "List", Car.class )
}
}

4. build.gradle.mustache - the template for the build.gradle

In order to generate the code run:
./bin/runscala.sh com.wordnik.swagger.codegen.BasicGroovyGenerator
Then generate a gradle project on top of the generated code and use it.