forked from loafle/openapi-generator-original
add back groovy code generator
This commit is contained in:
parent
5a6fb39aa5
commit
fb883e5f03
@ -0,0 +1,93 @@
|
|||||||
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import io.swagger.codegen.*;
|
||||||
|
import io.swagger.models.Operation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class GroovyClientCodegen extends JavaClientCodegen {
|
||||||
|
public static final String CONFIG_PACKAGE = "configPackage";
|
||||||
|
protected String title = "Petstore Server";
|
||||||
|
protected String configPackage = "";
|
||||||
|
protected String templateFileName = "api.mustache";
|
||||||
|
|
||||||
|
public GroovyClientCodegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
sourceFolder = projectFolder + File.separator + "groovy";
|
||||||
|
outputFolder = "generated-code/groovy";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".groovy");
|
||||||
|
apiTemplateFiles.put(templateFileName, ".groovy");
|
||||||
|
embeddedTemplateDir = templateDir = "Groovy";
|
||||||
|
|
||||||
|
apiPackage = "io.swagger.api";
|
||||||
|
modelPackage = "io.swagger.model";
|
||||||
|
configPackage = "io.swagger.configuration";
|
||||||
|
invokerPackage = "io.swagger.api";
|
||||||
|
artifactId = "swagger-spring-mvc-server";
|
||||||
|
|
||||||
|
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||||
|
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||||
|
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||||
|
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||||
|
additionalProperties.put("title", title);
|
||||||
|
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||||
|
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
|
||||||
|
|
||||||
|
supportedLibraries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CLIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "groovy";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Groovy API client (beta).";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
// clear model and api doc template as this codegen
|
||||||
|
// does not support auto-generated markdown doc at the moment
|
||||||
|
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||||
|
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
|
||||||
|
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
|
||||||
|
}
|
||||||
|
|
||||||
|
supportingFiles.clear();
|
||||||
|
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||||
|
// TODO readme to be added later
|
||||||
|
//supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiUtils.mustache",
|
||||||
|
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiUtils.groovy"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiName(String name) {
|
||||||
|
if (name.length() == 0) {
|
||||||
|
return "DefaultApi";
|
||||||
|
}
|
||||||
|
name = sanitizeName(name);
|
||||||
|
return camelize(name) + "Api";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigPackage(String configPackage) {
|
||||||
|
this.configPackage = configPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,9 @@
|
|||||||
package {{package}};
|
package {{package}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import groovyx.net.http.*
|
import groovyx.net.http.*
|
||||||
import static groovyx.net.http.ContentType.*
|
import static groovyx.net.http.ContentType.*
|
||||||
import static groovyx.net.http.Method.*
|
import static groovyx.net.http.Method.*
|
||||||
import {{invokerPackage}}.ApiUtils
|
import {{invokerPackage}}.ApiUtils
|
||||||
//-------------
|
|
||||||
|
|
||||||
{{#imports}}import {{import}}
|
{{#imports}}import {{import}}
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
@ -21,36 +16,37 @@ class {{classname}} {
|
|||||||
String basePath = "{{basePath}}"
|
String basePath = "{{basePath}}"
|
||||||
String versionPath = "/api/v1"
|
String versionPath = "/api/v1"
|
||||||
|
|
||||||
|
{{#operation}}
|
||||||
|
def {{operationId}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
||||||
|
// create path and map variables
|
||||||
|
String resourcePath = "{{path}}"
|
||||||
|
|
||||||
{{#operation}}
|
// query params
|
||||||
def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
def queryParams = [:]
|
||||||
// create path and map variables
|
def headerParams = [:]
|
||||||
String resourcePath = "{{path}}"
|
|
||||||
|
{{#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("{{paramName}}", String.valueOf({{paramName}}))
|
||||||
|
{{/queryParams}}
|
||||||
|
|
||||||
// query params
|
{{#headerParams}}
|
||||||
def queryParams = [:]
|
headerParams.put("{{paramName}}", {{paramName}})
|
||||||
def headerParams = [:]
|
{{/headerParams}}
|
||||||
|
|
||||||
{{#allParams}}
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
// verify required params are set
|
|
||||||
if({{/allParams}}{{#required}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/required}}{{#allParams}}) {
|
|
||||||
throw new RuntimeException("missing required params")
|
|
||||||
}
|
|
||||||
{{/allParams}}
|
|
||||||
|
|
||||||
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
|
|
||||||
queryParams.put("{{paramName}}", String.valueOf({{paramName}}))
|
|
||||||
{{/queryParams}}
|
|
||||||
|
|
||||||
{{#headerParams}}headerParams.put("{{paramName}}", {{paramName}})
|
|
||||||
{{/headerParams}}
|
|
||||||
|
|
||||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
|
||||||
"{{httpMethod}}", "{{returnContainer}}",
|
"{{httpMethod}}", "{{returnContainer}}",
|
||||||
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
|
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
|
||||||
|
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
@ -17,15 +17,26 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
||||||
maven { url "http://$artifactory:8080/artifactory/repo" }
|
maven { url "http://$artifactory:8080/artifactory/repo" }
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
swagger_annotations_version = "1.5.8"
|
||||||
|
jackson_version = "2.7.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
groovy "org.codehaus.groovy:groovy-all:2.0.5"
|
compile 'org.codehaus.groovy:groovy-all:2.4.6'
|
||||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
|
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||||
|
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
||||||
|
@ -6,6 +6,7 @@ io.swagger.codegen.languages.DartClientCodegen
|
|||||||
io.swagger.codegen.languages.FlashClientCodegen
|
io.swagger.codegen.languages.FlashClientCodegen
|
||||||
io.swagger.codegen.languages.FlaskConnexionCodegen
|
io.swagger.codegen.languages.FlaskConnexionCodegen
|
||||||
io.swagger.codegen.languages.GoClientCodegen
|
io.swagger.codegen.languages.GoClientCodegen
|
||||||
|
io.swagger.codegen.languages.GroovyClientCodegen
|
||||||
io.swagger.codegen.languages.JavaClientCodegen
|
io.swagger.codegen.languages.JavaClientCodegen
|
||||||
io.swagger.codegen.languages.JavaJerseyServerCodegen
|
io.swagger.codegen.languages.JavaJerseyServerCodegen
|
||||||
io.swagger.codegen.languages.JavaCXFServerCodegen
|
io.swagger.codegen.languages.JavaCXFServerCodegen
|
||||||
@ -41,4 +42,4 @@ io.swagger.codegen.languages.AkkaScalaClientCodegen
|
|||||||
io.swagger.codegen.languages.CsharpDotNet2ClientCodegen
|
io.swagger.codegen.languages.CsharpDotNet2ClientCodegen
|
||||||
io.swagger.codegen.languages.ClojureClientCodegen
|
io.swagger.codegen.languages.ClojureClientCodegen
|
||||||
io.swagger.codegen.languages.HaskellServantCodegen
|
io.swagger.codegen.languages.HaskellServantCodegen
|
||||||
io.swagger.codegen.languages.LumenServerCodegen
|
io.swagger.codegen.languages.LumenServerCodegen
|
||||||
|
42
samples/client/petstore/groovy/build.gradle
Normal file
42
samples/client/petstore/groovy/build.gradle
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
apply plugin: 'groovy'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
|
def artifactory = 'buildserver.supportspace.com'
|
||||||
|
group = 'com.supportspace'
|
||||||
|
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 {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
||||||
|
maven { url "http://$artifactory:8080/artifactory/repo" }
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
swagger_annotations_version = "1.5.8"
|
||||||
|
jackson_version = "2.7.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile 'org.codehaus.groovy:groovy-all:2.4.6'
|
||||||
|
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||||
|
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
@ -0,0 +1,50 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,184 @@
|
|||||||
|
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 = "/pet"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/pet/{petId}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (petId == null) {
|
||||||
|
throw new RuntimeException("missing required params petId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/pet/findByStatus"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (status == null) {
|
||||||
|
throw new RuntimeException("missing required params status")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"null".equals(String.valueOf(status)))
|
||||||
|
queryParams.put("status", String.valueOf(status))
|
||||||
|
|
||||||
|
|
||||||
|
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 variables
|
||||||
|
String resourcePath = "/pet/findByTags"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (tags == null) {
|
||||||
|
throw new RuntimeException("missing required params tags")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"null".equals(String.valueOf(tags)))
|
||||||
|
queryParams.put("tags", String.valueOf(tags))
|
||||||
|
|
||||||
|
|
||||||
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
|
"GET", "array",
|
||||||
|
Pet.class )
|
||||||
|
|
||||||
|
}
|
||||||
|
def getPetById ( Long petId, Closure onSuccess, Closure onFailure) {
|
||||||
|
// create path and map variables
|
||||||
|
String resourcePath = "/pet/{petId}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (petId == null) {
|
||||||
|
throw new RuntimeException("missing required params petId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/pet"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/pet/{petId}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (petId == null) {
|
||||||
|
throw new RuntimeException("missing required params petId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/pet/{petId}/uploadImage"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (petId == null) {
|
||||||
|
throw new RuntimeException("missing required params petId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
|
"POST", "",
|
||||||
|
ModelApiResponse.class )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
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.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 = "/store/order/{orderId}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (orderId == null) {
|
||||||
|
throw new RuntimeException("missing required params orderId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
|
"DELETE", "",
|
||||||
|
null )
|
||||||
|
|
||||||
|
}
|
||||||
|
def getInventory ( Closure onSuccess, Closure onFailure) {
|
||||||
|
// create path and map variables
|
||||||
|
String resourcePath = "/store/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 = "/store/order/{orderId}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (orderId == null) {
|
||||||
|
throw new RuntimeException("missing required params orderId")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/store/order"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
|
"POST", "",
|
||||||
|
Order.class )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,185 @@
|
|||||||
|
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.*;
|
||||||
|
|
||||||
|
@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 = "/user"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/user/createWithArray"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/user/createWithList"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (body == null) {
|
||||||
|
throw new RuntimeException("missing required params body")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/user/{username}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (username == null) {
|
||||||
|
throw new RuntimeException("missing required params username")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/user/{username}"
|
||||||
|
|
||||||
|
// query params
|
||||||
|
def queryParams = [:]
|
||||||
|
def headerParams = [:]
|
||||||
|
|
||||||
|
// verify required params are set
|
||||||
|
if (username == null) {
|
||||||
|
throw new RuntimeException("missing required params username")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = "/user/login"
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "/user/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 = "/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")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||||
|
"PUT", "",
|
||||||
|
null )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,218 @@
|
|||||||
|
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 )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
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 )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,200 @@
|
|||||||
|
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 )
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user