All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Groovy.api.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
package {{package}};

import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import {{invokerPackage}}.ApiUtils

{{#imports}}import {{import}}
{{/imports}}

import java.util.*;

@Mixin(ApiUtils)
{{#operations}}
class {{classname}} {
    String basePath = "{{{basePath}}}"
    String versionPath = "/api/v1"

    {{#operation}}
    def {{operationId}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure)  {
        // create path and map path parameters (TODO)
        String resourcePath = "{{{path}}}"

        // 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.put("{{baseName}}", String.valueOf({{paramName}}))
        {{/queryParams}}

        {{#headerParams}}
        headerParams.put("{{baseName}}", {{paramName}})
        {{/headerParams}}

        // Also still TODO: form params, body param

        invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
                    "{{httpMethod}}", "{{returnContainer}}",
                    {{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
                    
    }
    {{/operation}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy