forked from loafle/openapi-generator-original
Merge pull request #4 from fehguy/master
fixed issues with requiredParams
This commit is contained in:
commit
907c32af95
128
conf/ruby/sample/build.xml
Normal file
128
conf/ruby/sample/build.xml
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project name="swagger-sample-scala-lib" xmlns:ivy="antlib:org.apache.ivy.ant" default="build.all" basedir=".">
|
||||||
|
<property environment="env" />
|
||||||
|
<property name="version.identifier" value="1.0" />
|
||||||
|
<property name="artifact.ext" value="jar" />
|
||||||
|
<property name="organization" value="wordnik" />
|
||||||
|
<property name="module" value="${ant.project.name}" />
|
||||||
|
|
||||||
|
<!-- default dirs for the build -->
|
||||||
|
<mkdir dir="lib"/>
|
||||||
|
<mkdir dir="lib/ext"/>
|
||||||
|
|
||||||
|
<condition property="scala.home" value="${env.SCALA_HOME}">
|
||||||
|
<isset property="env.SCALA_HOME" />
|
||||||
|
</condition>
|
||||||
|
|
||||||
|
<path id="scala.classpath">
|
||||||
|
<fileset dir="${scala.home}/lib">
|
||||||
|
<include name="scala**.jar" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<ivy:settings file="ivysettings.xml" />
|
||||||
|
|
||||||
|
<taskdef resource="scala/tools/ant/antlib.xml">
|
||||||
|
<classpath>
|
||||||
|
<fileset dir="lib">
|
||||||
|
<include name="scala**.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="${scala.home}/lib">
|
||||||
|
<include name="scala**.jar" />
|
||||||
|
</fileset>
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<!-- this is the output module -->
|
||||||
|
<property name="module" value="${ant.project.name}" />
|
||||||
|
|
||||||
|
<target name="build.all" depends="clean, resolve, fastcompile" description="builds the module (default target)" />
|
||||||
|
|
||||||
|
<target name="clean" description="cleans the project folder">
|
||||||
|
<mkdir dir="build" />
|
||||||
|
<echo message="deleting build files" />
|
||||||
|
<delete quiet="true">
|
||||||
|
<fileset dir="build">
|
||||||
|
<include name="*.jar" />
|
||||||
|
<include name="*.xml" />
|
||||||
|
</fileset>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete dir="build/main" quiet="true" />
|
||||||
|
|
||||||
|
<delete dir="dist" quiet="true" />
|
||||||
|
|
||||||
|
<!-- libraries handled by ivy -->
|
||||||
|
<echo message="deleting libs handled by ivy" />
|
||||||
|
<delete>
|
||||||
|
<fileset dir="lib">
|
||||||
|
<include name="*.jar" />
|
||||||
|
<include name="*.zip" />
|
||||||
|
</fileset>
|
||||||
|
</delete>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- copies ONLY the swagger-sample jar to dist-->
|
||||||
|
<target name="fastdist" depends="fastcompile">
|
||||||
|
<copy todir="dist/lib">
|
||||||
|
<fileset dir="build">
|
||||||
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- copies all dependencies into the lib folder -->
|
||||||
|
<target name="resolve" description="retreive dependencies with ivy">
|
||||||
|
<ivy:retrieve pattern="${basedir}/lib/[artifact]-[revision].[ext]" conf="build" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="fastcompile" description="builds the module without artifact resolution or cleaning">
|
||||||
|
<delete quiet="true" file="build/${organization}-${artifact}-*.${artifact.ext}" />
|
||||||
|
<mkdir dir="build" />
|
||||||
|
<mkdir dir="build/main" />
|
||||||
|
<mkdir dir="build/main/java" />
|
||||||
|
|
||||||
|
<javac srcdir="src/main/java" debug="true" destdir="build/main/java">
|
||||||
|
<classpath>
|
||||||
|
<fileset dir="lib">
|
||||||
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="lib/ext">
|
||||||
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<pathelement location="build/main/java" />
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
|
||||||
|
|
||||||
|
<scalac srcdir="src/main/java:src/main/scala" destdir="build/main/java">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="build/main/java" />
|
||||||
|
<fileset dir="lib">
|
||||||
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="lib/ext">
|
||||||
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="${scala.home}/lib"/>
|
||||||
|
</classpath>
|
||||||
|
<include name="**/*.scala" />
|
||||||
|
<include name="**/*.java" />
|
||||||
|
</scalac>
|
||||||
|
|
||||||
|
<jar jarfile="build/${module}-${version.identifier}.${artifact.ext}">
|
||||||
|
<fileset dir="build/main/java" />
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- cleans up the dist -->
|
||||||
|
<target name="dist.clean" description="cleans the distribution folder">
|
||||||
|
<delete quiet="true" dir="dist" />
|
||||||
|
<delete quiet="true" file="dist.zip" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dependency.tree" description="builds a graphml dependency diagram for viewing with yEd">
|
||||||
|
<ivy:report conf="build" graph="true" todir="." outputpattern="[artifact]-[revision].[ext]" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
31
conf/ruby/sample/ivy.xml
Normal file
31
conf/ruby/sample/ivy.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<ivy-module version="2.0">
|
||||||
|
<info organisation="wordnik" module="sample-java-lib"/>
|
||||||
|
<configurations>
|
||||||
|
<conf name="build" description="build wordnik-java"/>
|
||||||
|
<conf name="test" visibility="public"/>
|
||||||
|
<conf name="source" visibility="public"/>
|
||||||
|
<conf name="pom" visibility="public"/>
|
||||||
|
</configurations>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- jersey dependencies -->
|
||||||
|
<dependency org="junit" name="junit" rev="4.4" conf="build->default"/>
|
||||||
|
<dependency org="com.sun.jersey" name="jersey-json" rev="1.4" conf="build->default"/>
|
||||||
|
<dependency org="com.sun.jersey" name="jersey-client" rev="1.4" conf="build->default"/>
|
||||||
|
<dependency org="com.sun.jersey" name="jersey-server" rev="1.4" conf="build->default"/>
|
||||||
|
<dependency org="com.sun.jersey" name="jersey-core" rev="1.4" conf="build->default"/>
|
||||||
|
<dependency org="asm" name="asm-parent" rev="3.1" conf="build->default"/>
|
||||||
|
<dependency org="commons-beanutils" name="commons-beanutils" rev="1.8.0" conf="build->default"/>
|
||||||
|
<dependency org="org.antlr" name="stringtemplate" rev="3.2" conf="build->default"/>
|
||||||
|
<!-- jackson jars -->
|
||||||
|
<dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.7.1" conf="build->default"/>
|
||||||
|
<dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.7.1" conf="build->default"/>
|
||||||
|
<dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.7.1" conf="build->default"/>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.2" conf="test->default">
|
||||||
|
<exclude org="asm" name="asm-tree"/>
|
||||||
|
<exclude org="asm" name="asm"/>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</ivy-module>
|
23
conf/ruby/sample/ivysettings.xml
Normal file
23
conf/ruby/sample/ivysettings.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ivysettings>
|
||||||
|
<settings defaultResolver="chained" />
|
||||||
|
<property name="ivy.checksums" value=""/>
|
||||||
|
<property name="ivy.local.default.root" value="${ivy.default.ivy.user.dir}/local"
|
||||||
|
override="false" />
|
||||||
|
<property name="ivy.local.default.ivy.pattern"
|
||||||
|
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
|
||||||
|
override="false" />
|
||||||
|
<property name="ivy.local.default.artifact.pattern"
|
||||||
|
value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
|
||||||
|
override="false" />
|
||||||
|
<resolvers>
|
||||||
|
<chain name="chained" returnFirst="true">
|
||||||
|
<filesystem name="local">
|
||||||
|
<ivy pattern="${ivy.local.default.root}/${ivy.local.default.ivy.pattern}" />
|
||||||
|
<artifact pattern="${ivy.local.default.root}/${ivy.local.default.artifact.pattern}" />
|
||||||
|
</filesystem>
|
||||||
|
<ibiblio name="ibiblio" m2compatible="true" />
|
||||||
|
<ibiblio name="javanet" root="http://download.java.net/maven/2/" m2compatible="true" />
|
||||||
|
</chain>
|
||||||
|
</resolvers>
|
||||||
|
</ivysettings>
|
27
conf/ruby/sample/java_code_gen_conf.json
Normal file
27
conf/ruby/sample/java_code_gen_conf.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"apiUrl":"http://localhost:8002/api/",
|
||||||
|
|
||||||
|
"apiKey":"special-key",
|
||||||
|
|
||||||
|
"defaultServiceBaseClass":"Object",
|
||||||
|
|
||||||
|
"defaultModelBaseClass":"Object",
|
||||||
|
|
||||||
|
"serviceBaseClasses":{},
|
||||||
|
|
||||||
|
"defaultModelImports":[],
|
||||||
|
|
||||||
|
"defaultServiceImports":[],
|
||||||
|
|
||||||
|
"modelPackageName":"com.wordnik.swagger.sample.sdk.java.model",
|
||||||
|
|
||||||
|
"apiPackageName":"com.wordnik.swagger.sample.sdk.java.api",
|
||||||
|
|
||||||
|
"ignoreMethods":[],
|
||||||
|
|
||||||
|
"ignoreModels":[],
|
||||||
|
|
||||||
|
"outputDirectory":"../swagger-sample-app/sdk-libs/src/main/java/com/wordnik/swagger/sample/sdk/java",
|
||||||
|
|
||||||
|
"libraryHome":"../swagger-sample-app/sdk-libs"
|
||||||
|
}
|
42
conf/ruby/sample/lib-test-data.json
Normal file
42
conf/ruby/sample/lib-test-data.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"userList":[
|
||||||
|
{
|
||||||
|
"username":"testuser1",
|
||||||
|
"password":"password1",
|
||||||
|
"email":"test1@dummy.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username":"testuser2",
|
||||||
|
"password":"password2",
|
||||||
|
"email":"test2@dummy.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"petList":[
|
||||||
|
{
|
||||||
|
"id":101,
|
||||||
|
"name":"pet1",
|
||||||
|
"photoUrls":["url1","url2"],
|
||||||
|
"tags":[
|
||||||
|
{
|
||||||
|
"id":1,
|
||||||
|
"name":"tag1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":2,
|
||||||
|
"name":"tag2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status":"available",
|
||||||
|
"category":{"id":1,"name":"cat1"}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"orderList":[
|
||||||
|
{
|
||||||
|
"id":101,
|
||||||
|
"petId":1,
|
||||||
|
"quantity":1,
|
||||||
|
"status":"placed",
|
||||||
|
"shipDate":13456789
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
265
conf/ruby/sample/lib-test-script.json
Normal file
265
conf/ruby/sample/lib-test-script.json
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
{
|
||||||
|
"resources" : [
|
||||||
|
{
|
||||||
|
"id" : 1,
|
||||||
|
"name" : "Find Per by Id",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/pet.{format}/{petId}",
|
||||||
|
"suggestedMethodName" : "getPetById"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 2,
|
||||||
|
"name" : "Find pets by status",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/pet.{format}/findByStatus",
|
||||||
|
"suggestedMethodName" : "findPetsByStatus"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 3,
|
||||||
|
"name" : "Find pets by tags",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/pet.{format}/findByTags",
|
||||||
|
"suggestedMethodName" : "findPetsByTags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 4,
|
||||||
|
"name" : "Add a pet",
|
||||||
|
"httpMethod" : "POST",
|
||||||
|
"path" : "/pet.{format}",
|
||||||
|
"suggestedMethodName" : "addPet"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 5,
|
||||||
|
"name" : "Update a pet",
|
||||||
|
"httpMethod" : "PUT",
|
||||||
|
"path" : "/pet.{format}",
|
||||||
|
"suggestedMethodName" : "updatePet"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 6,
|
||||||
|
"name" : "Create user",
|
||||||
|
"httpMethod" : "POST",
|
||||||
|
"path" : "/user.{format}",
|
||||||
|
"suggestedMethodName" : "createUser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 7,
|
||||||
|
"name" : "Update user",
|
||||||
|
"httpMethod" : "PUT",
|
||||||
|
"path" : "/user.{format}/{username}",
|
||||||
|
"suggestedMethodName" : "updateUser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 8,
|
||||||
|
"name" : "Delete user",
|
||||||
|
"httpMethod" : "DELETE",
|
||||||
|
"path" : "/user.{format}/{username}",
|
||||||
|
"suggestedMethodName" : "deleteUser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 9,
|
||||||
|
"name" : "Get user by user name",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/user.{format}/{username}",
|
||||||
|
"suggestedMethodName" : "getUserByName"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 10,
|
||||||
|
"name" : "Login",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/user.{format}/login",
|
||||||
|
"suggestedMethodName" : "loginUser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 11,
|
||||||
|
"name" : "Logout",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/user.{format}/logout",
|
||||||
|
"suggestedMethodName" : "logoutUser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 12,
|
||||||
|
"name" : "Find order by id",
|
||||||
|
"httpMethod" : "GET",
|
||||||
|
"path" : "/store.{format}/order/{orderId}",
|
||||||
|
"suggestedMethodName" : "getOrderById"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 13,
|
||||||
|
"name" : "Delete order by id",
|
||||||
|
"httpMethod" : "DELETE",
|
||||||
|
"path" : "/store.{format}/order/{orderId}",
|
||||||
|
"suggestedMethodName" : "deleteOrder"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 14,
|
||||||
|
"name" : "Create order",
|
||||||
|
"httpMethod" : "POST",
|
||||||
|
"path" : "/store.{format}/order",
|
||||||
|
"suggestedMethodName" : "placeOrder"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"testSuites" : [
|
||||||
|
{
|
||||||
|
"id" : 1,
|
||||||
|
"name" : "Test User service related APIs",
|
||||||
|
"testCases" : [
|
||||||
|
{
|
||||||
|
"name" : "Create User",
|
||||||
|
"id" : 1,
|
||||||
|
"resourceId" : 6,
|
||||||
|
"input" : {
|
||||||
|
"postData":"${input.userList[0]}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(1.1)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "EXCEPTION"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Login User",
|
||||||
|
"id" : 2,
|
||||||
|
"resourceId" : 10,
|
||||||
|
"input" : {
|
||||||
|
"username":"${input.userList[0].username}",
|
||||||
|
"password":"${input.userList[0].password}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(1.2)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "EXCEPTION"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Find user by name",
|
||||||
|
"id" : 3,
|
||||||
|
"resourceId" : 9,
|
||||||
|
"input" : {
|
||||||
|
"username":"${input.userList[0].username}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(1.3).username}",
|
||||||
|
"condition" : "==",
|
||||||
|
"expectedOutput" : "${input.userList[0].username}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Delete user by name",
|
||||||
|
"id" : 4,
|
||||||
|
"resourceId" : 9,
|
||||||
|
"input" : {
|
||||||
|
"username":"${input.userList[0].username}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(1.4)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "EXCEPTION"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 2,
|
||||||
|
"name" : "Test Pet service related APIs",
|
||||||
|
"testCases" : [
|
||||||
|
{
|
||||||
|
"name" : "Add pet",
|
||||||
|
"id" : 1,
|
||||||
|
"resourceId" : 4,
|
||||||
|
"input" : {
|
||||||
|
"postData":"${input.petList[0]}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(2.1)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "EXCEPTION"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Find pet by id",
|
||||||
|
"id" : 2,
|
||||||
|
"resourceId" : 1,
|
||||||
|
"input" : {
|
||||||
|
"petId":"1"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(2.2)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "NULL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Find pet by status",
|
||||||
|
"id" : 3,
|
||||||
|
"resourceId" : 2,
|
||||||
|
"input" : {
|
||||||
|
"status":"available,sold,pending"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(2.3).size}",
|
||||||
|
"condition" : ">",
|
||||||
|
"expectedOutput" : "0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 3,
|
||||||
|
"name" : "Test Store service related APIs",
|
||||||
|
"testCases" : [
|
||||||
|
{
|
||||||
|
"name" : "Find order by id",
|
||||||
|
"id" : 1,
|
||||||
|
"resourceId" : 12,
|
||||||
|
"input" : {
|
||||||
|
"orderId":"1"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(3.1)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "NULL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Place order",
|
||||||
|
"id" : 2,
|
||||||
|
"resourceId" : 14,
|
||||||
|
"input" : {
|
||||||
|
"postData":"${input.orderList[0]}"
|
||||||
|
},
|
||||||
|
"assertions" : [
|
||||||
|
{
|
||||||
|
"actualOutput" : "${output(1.2)}",
|
||||||
|
"condition" : "!=",
|
||||||
|
"expectedOutput" : "EXCEPTION"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
conf/ruby/structure/swagger.rb
Normal file
1
conf/ruby/structure/swagger.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
# nothing to see yet
|
31
conf/ruby/templates/EnumObject.st
Normal file
31
conf/ruby/templates/EnumObject.st
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2011 Wordnik, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package $packageName$
|
||||||
|
|
||||||
|
$imports:{ import |
|
||||||
|
import $import$;
|
||||||
|
}$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $enum.description$
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||||
|
* @author tony
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
object $className$ {
|
||||||
|
$values: { value | var $value.name$ = $value.value$};separator="\n"$
|
||||||
|
}
|
21
conf/ruby/templates/ModelObject.st
Normal file
21
conf/ruby/templates/ModelObject.st
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
class $className$Model
|
||||||
|
attr_accessor $fields:{ field | :$field.fieldDefinition.name$};separator=", "$
|
||||||
|
$fields:{ field |
|
||||||
|
$if(field.required)$ validate_presence_of :$field.fieldDefinition.name$$endif$
|
||||||
|
}$
|
||||||
|
|
||||||
|
# TODO: move this to base class
|
||||||
|
def initialize(attributes = {})
|
||||||
|
attributes.symbolize_and_underscore_keys!
|
||||||
|
|
||||||
|
# loop over incoming attributes, only assign to valid attr_accessor props
|
||||||
|
$fields:{ field |
|
||||||
|
if(UserModel.respond_to? :$field.fieldDefinition.name$) self.$field.fieldDefinition.name$ = attributes[:$field.fieldDefinition.name$]
|
||||||
|
}$
|
||||||
|
|
||||||
|
# if(UserModel.respond_to? :word) self.word = attributes[:word]
|
||||||
|
# Zap any whitespace and bad encoding
|
||||||
|
# attributes[:name] &&= attributes[:name].strip.squeeze(' ').force_encoding('UTF-8')
|
||||||
|
# super(attributes)
|
||||||
|
end
|
||||||
|
end
|
47
conf/ruby/templates/ResourceObject.st
Normal file
47
conf/ruby/templates/ResourceObject.st
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module $resource$
|
||||||
|
|
||||||
|
$methods:{ method |
|
||||||
|
def $method.name$(opts={})
|
||||||
|
$if(method.pathParameters)$ requiredKeys=[:$method.pathParameters:{ param | $param.name$};separator=", "$]$endif$
|
||||||
|
$if(method.queryParameters)$ queryparamKeys=[:$method.queryParameters:{ param | $param.name$};separator=", "$]$endif$
|
||||||
|
|
||||||
|
$if(method.pathParameters)$
|
||||||
|
#check required options
|
||||||
|
requiredKeys.each do |key|
|
||||||
|
raise "#{key} is required" unless options.has_key?(key)
|
||||||
|
end
|
||||||
|
$endif$
|
||||||
|
|
||||||
|
|
||||||
|
# set default values and merge with input
|
||||||
|
options = {
|
||||||
|
$if(method.arguments)$$method.arguments:{ param | $if(param.defaultValue)$ :$param.name$="$param.defaultValue$"$endif$}$$endif$
|
||||||
|
}.merge(opts)
|
||||||
|
|
||||||
|
#resource path
|
||||||
|
path = "$method.resourcePath$".sub('{format}', '.json')
|
||||||
|
|
||||||
|
$if(method.pathParameters)$
|
||||||
|
# sub pathparams
|
||||||
|
$method.pathParameters:{ param |
|
||||||
|
path.sub!('{$param.name$}', URI.encode(options[:$param.name$]))
|
||||||
|
}$$endif$
|
||||||
|
#pull querystring keys from options
|
||||||
|
queryopts = options.select do |key,value|
|
||||||
|
queryparamKeys.include? key
|
||||||
|
end
|
||||||
|
|
||||||
|
$if(method.hasResponseValue)$
|
||||||
|
results = Swagger::request.new(:get, path, queryopts, nil)
|
||||||
|
$if(method.returnValueList)$
|
||||||
|
output = results.map {|result| $method.returnValue$.new(result)}
|
||||||
|
$else$
|
||||||
|
output = $method.returnValue$.new(result)
|
||||||
|
$endif$
|
||||||
|
$else$
|
||||||
|
Swagger::request.new(:get, path, queryopts, nil)
|
||||||
|
$endif$
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
}$
|
5
conf/ruby/templates/VersionChecker.st
Normal file
5
conf/ruby/templates/VersionChecker.st
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module $resource$
|
||||||
|
def get_compatible_version(*args)
|
||||||
|
'$apiVersion$'
|
||||||
|
end
|
||||||
|
|
@ -24,15 +24,29 @@ public class MethodArgument {
|
|||||||
public static String ARGUMENT_OBJECT = "Object";
|
public static String ARGUMENT_OBJECT = "Object";
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String dataType;
|
private String dataType;
|
||||||
|
|
||||||
private String allowedValues;
|
private String allowedValues;
|
||||||
|
|
||||||
private String inputModelClassArgument;
|
private String inputModelClassArgument;
|
||||||
private String methodNameFromModelClass;
|
private String methodNameFromModelClass;
|
||||||
|
private String defaultValue;
|
||||||
|
private boolean required;
|
||||||
|
|
||||||
|
public String getDefaultValue(){
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultValue(String defaultValue){
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRequired() {
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequired(boolean required){
|
||||||
|
this.required = required;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -52,17 +52,32 @@ public class LanguageConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setOutputDirectory(String outputDirectory) {
|
public void setOutputDirectory(String outputDirectory) {
|
||||||
|
|
||||||
if(outputDirectory == null || outputDirectory.length() == 0){
|
if(outputDirectory == null || outputDirectory.length() == 0){
|
||||||
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
||||||
}
|
}
|
||||||
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
||||||
|
|
||||||
|
|
||||||
this.modelClassLocation = outputDirectory + "/model/";
|
this.modelClassLocation = outputDirectory + "/model/";
|
||||||
this.resourceClassLocation = outputDirectory + "/api/";
|
this.resourceClassLocation = outputDirectory + "/api/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOutputDirectory(String outputDirectory, String modelDirectory, String resourceDirectory){
|
||||||
|
if(outputDirectory == null || outputDirectory.length() == 0){
|
||||||
|
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
||||||
|
}
|
||||||
|
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
||||||
|
|
||||||
|
// add leading + trailing slashes
|
||||||
|
if(!modelDirectory.startsWith("/")) modelDirectory = "/" + modelDirectory;
|
||||||
|
if(!modelDirectory.endsWith("/")) modelDirectory = modelDirectory + "/";
|
||||||
|
|
||||||
|
if(!resourceDirectory.startsWith("/")) resourceDirectory = "/" + resourceDirectory;
|
||||||
|
if(!resourceDirectory.endsWith("/")) resourceDirectory = resourceDirectory + "/";
|
||||||
|
|
||||||
|
this.modelClassLocation = outputDirectory + modelDirectory;
|
||||||
|
this.resourceClassLocation = outputDirectory + resourceDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
public String getModelClassLocation() {
|
public String getModelClassLocation() {
|
||||||
return modelClassLocation;
|
return modelClassLocation;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,200 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2011 Wordnik, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.wordnik.swagger.codegen.config.ruby
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.config.DataTypeMappingProvider
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.config.NamingPolicyProvider
|
||||||
|
import com.wordnik.swagger.codegen.config.common.UnderscoreNamingPolicyProvider
|
||||||
|
|
||||||
|
import scala.collection.mutable._
|
||||||
|
import scala.collection.JavaConversions._
|
||||||
|
|
||||||
|
object RubyDataTypeMappingProvider {
|
||||||
|
val primitiveValueMap = Map("string" -> "String",
|
||||||
|
"String" -> "String",
|
||||||
|
"int" -> "int",
|
||||||
|
"integer" -> "int",
|
||||||
|
"Integer" -> "int",
|
||||||
|
"boolean" -> "boolean",
|
||||||
|
"Boolean" -> "boolean",
|
||||||
|
"long" -> "long",
|
||||||
|
"Long" -> "long",
|
||||||
|
"float" -> "float",
|
||||||
|
"Float" -> "float",
|
||||||
|
"Date" -> "Date",
|
||||||
|
"date" -> "Date")
|
||||||
|
|
||||||
|
val primitiveObjectMap = Map("string" -> "String",
|
||||||
|
"String" -> "String",
|
||||||
|
"java.lang.String" -> "String",
|
||||||
|
"int" -> "Integer",
|
||||||
|
"integer" -> "Integer",
|
||||||
|
"Integer" -> "Integer",
|
||||||
|
"java.lang.Integer" -> "Integer",
|
||||||
|
"boolean" -> "Boolean",
|
||||||
|
"Boolean" -> "Boolean",
|
||||||
|
"java.lang.Boolean" -> "Boolean",
|
||||||
|
"long" -> "Long",
|
||||||
|
"Long" -> "Long",
|
||||||
|
"java.lang.Long" -> "Long",
|
||||||
|
"float" -> "Float",
|
||||||
|
"Float" -> "Float",
|
||||||
|
"java.lang.Float" -> "Float",
|
||||||
|
"Date" -> "Date",
|
||||||
|
"date" -> "Date",
|
||||||
|
"java.util.Date" -> "Date")
|
||||||
|
}
|
||||||
|
|
||||||
|
class RubyDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||||
|
val nameGenerator = new UnderscoreNamingPolicyProvider()
|
||||||
|
|
||||||
|
def isPrimitiveType(input: String): Boolean = {
|
||||||
|
RubyDataTypeMappingProvider.primitiveObjectMap.contains(input) match {
|
||||||
|
case true => true
|
||||||
|
case _ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getListReturnTypeSignature(typeClass: String): String = {
|
||||||
|
return "List[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMapReturnTypeSignature(typeClass: String): String = {
|
||||||
|
return "Map[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def getSetReturnTypeSignature(typeClass: String): String = {
|
||||||
|
return "Set[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def generateVariableInitialization(typeClass:String):String = "=_"
|
||||||
|
|
||||||
|
def generateListInitialization(typeClass: String): String = {
|
||||||
|
return " new ListBuffer[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def generateMapInitialization(typeClass: String): String = {
|
||||||
|
return " new HashMap[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def generateSetInitialization(typeClass: String): String = {
|
||||||
|
return " new HashSet[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
def getListIncludes(): java.util.List[String] = {
|
||||||
|
List("scala.collection.mutable.ListBuffer")
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMapIncludes(): java.util.List[String] = {
|
||||||
|
List("java.util.Map", "java.util.HashMap")
|
||||||
|
}
|
||||||
|
|
||||||
|
def getSetIncludes: java.util.List[String] = {
|
||||||
|
List("java.util.Set", "java.util.HashSet")
|
||||||
|
}
|
||||||
|
|
||||||
|
def getDateIncludes: java.util.List[String] = {
|
||||||
|
List("java.util.Date")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the short name of the class the class.
|
||||||
|
* Input can be MAP, LIST or regular string. In case of map or list the class name will be class name
|
||||||
|
* that map or list is returning.
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
def getGenericType(inputType: String): String = {
|
||||||
|
var classShortName = ""
|
||||||
|
if (inputType.startsWith("List[")) {
|
||||||
|
classShortName = inputType.substring(5, inputType.length() - 1);
|
||||||
|
classShortName = getClassType(classShortName, true);
|
||||||
|
} else if (inputType.startsWith("Map[")) {
|
||||||
|
classShortName = inputType.substring(4, inputType.length() - 1)
|
||||||
|
classShortName = getClassType(classShortName, true)
|
||||||
|
} else if (inputType.startsWith("Set[")) {
|
||||||
|
classShortName = inputType.substring(4, inputType.length() - 1)
|
||||||
|
classShortName = getClassType(classShortName, true)
|
||||||
|
} else if (inputType.equalsIgnoreCase("ok")) {
|
||||||
|
classShortName = ""
|
||||||
|
} else {
|
||||||
|
classShortName = getClassType(inputType, true)
|
||||||
|
}
|
||||||
|
classShortName
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the syntax for defintion of an object of type and name
|
||||||
|
*
|
||||||
|
* @param argumentType
|
||||||
|
* @param argumentName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
def getArgumentDefinition(argumentType: String, argumentName: String): String = {
|
||||||
|
argumentName + ":" + argumentType
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the class of the expected return value for a type string. Examples of type Strings are int, User, List[User]
|
||||||
|
* If the type string is a collection type like a map or list the string value returned would be the class
|
||||||
|
* that map or list is returning.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
def getClassType(input: String, primitiveObject: Boolean): String = {
|
||||||
|
if (input.equalsIgnoreCase("void") || input.equalsIgnoreCase("ok")) {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
var classShortName = ""
|
||||||
|
if (input.startsWith("List[")) {
|
||||||
|
classShortName = input.substring(5, input.length() - 1);
|
||||||
|
classShortName = "List[" + getClassName(classShortName, true) + "]";
|
||||||
|
} else if (input.startsWith("Map[")) {
|
||||||
|
classShortName = input.substring(4, input.length() - 1);
|
||||||
|
classShortName = "Map[" + getClassName(classShortName, true) + "]";
|
||||||
|
} else if (input.startsWith("Set[")) {
|
||||||
|
classShortName = input.substring(4, input.length() - 1);
|
||||||
|
classShortName = "Set[" + getClassName(classShortName, true) + "]";
|
||||||
|
} else {
|
||||||
|
classShortName = getClassName(input, true);
|
||||||
|
}
|
||||||
|
classShortName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the data type is primitive and it is expecting object structure then return primitive objects
|
||||||
|
* else return primitive types
|
||||||
|
* @param type
|
||||||
|
* @param primitiveObject -- indicates if the object is primitive or not
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
def getClassName(input: String, primitiveObject: Boolean): String = {
|
||||||
|
isPrimitiveType(input) match {
|
||||||
|
case true => {
|
||||||
|
if (primitiveObject) {
|
||||||
|
RubyDataTypeMappingProvider.primitiveObjectMap(input)
|
||||||
|
} else {
|
||||||
|
RubyDataTypeMappingProvider.primitiveValueMap(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _ => nameGenerator.applyClassNamingPolicy(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2011 Wordnik, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.wordnik.swagger.codegen.config.ruby
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.LibraryCodeGenerator
|
||||||
|
import com.wordnik.swagger.codegen.config.LanguageConfiguration
|
||||||
|
import com.wordnik.swagger.codegen.config.common.UnderscoreNamingPolicyProvider
|
||||||
|
import com.wordnik.swagger.codegen.exception.CodeGenerationException
|
||||||
|
import com.wordnik.swagger.codegen.util.FileUtil
|
||||||
|
import java.io.File
|
||||||
|
import com.wordnik.swagger.codegen.resource.EndpointOperation
|
||||||
|
|
||||||
|
object RubyLibCodeGen {
|
||||||
|
def main(args: Array[String]) = {
|
||||||
|
val codeGenerator = args.length match {
|
||||||
|
case 1 => new RubyLibCodeGen(args(0))
|
||||||
|
case 4 => {
|
||||||
|
var apiServerURL = args(0)
|
||||||
|
if (!apiServerURL.endsWith("/")) {
|
||||||
|
apiServerURL = apiServerURL + "/"
|
||||||
|
}
|
||||||
|
val apiKey = args(1);
|
||||||
|
val packageName = args(2)
|
||||||
|
var libraryHome = args(3)
|
||||||
|
if (libraryHome.endsWith("/")) {
|
||||||
|
libraryHome = libraryHome.substring(0, libraryHome.length() - 1)
|
||||||
|
}
|
||||||
|
val modelPackageName = packageName + ".models"
|
||||||
|
val apiPackageName = packageName + ".resources"
|
||||||
|
val classOutputDir = libraryHome + "/src/main/ruby/lib/" + packageName.replace(".", "/")
|
||||||
|
new RubyLibCodeGen(apiServerURL, apiKey, modelPackageName, apiPackageName, classOutputDir, libraryHome)
|
||||||
|
}
|
||||||
|
case _ => throw new CodeGenerationException("Invalid number of arguments passed: No command line argument was passed to the program for config json")
|
||||||
|
}
|
||||||
|
codeGenerator.generateCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RubyLibCodeGen (
|
||||||
|
apiServerURL: String,
|
||||||
|
apiKey: String,
|
||||||
|
modelPackageName: String,
|
||||||
|
apiPackageName: String,
|
||||||
|
classOutputDir: String,
|
||||||
|
libraryHome: String,
|
||||||
|
configPath: String) extends LibraryCodeGenerator {
|
||||||
|
|
||||||
|
// don't want to generate input models
|
||||||
|
EndpointOperation.setArgCountForInputModel(10000)
|
||||||
|
|
||||||
|
if (null != configPath) {
|
||||||
|
initializeWithConfigPath(configPath)
|
||||||
|
this.setDataTypeMappingProvider(new RubyDataTypeMappingProvider())
|
||||||
|
this.setNameGenerator(new UnderscoreNamingPolicyProvider())
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
initialize(apiServerURL, apiKey, modelPackageName, apiPackageName, classOutputDir, libraryHome)
|
||||||
|
setDataTypeMappingProvider(new RubyDataTypeMappingProvider())
|
||||||
|
setNameGenerator(new UnderscoreNamingPolicyProvider())
|
||||||
|
}
|
||||||
|
|
||||||
|
def this(apiServerURL: String, apiKey: String, modelPackageName: String, apiPackageName: String, classOutputDir: String, libraryHome: String) = this(apiServerURL, apiKey, modelPackageName, apiPackageName, classOutputDir, libraryHome, null)
|
||||||
|
def this(configPath: String) = this(null, null, null, null, null, null, configPath)
|
||||||
|
|
||||||
|
override def initializeLangConfig(config: LanguageConfiguration): LanguageConfiguration = {
|
||||||
|
config.setClassFileExtension(".rb");
|
||||||
|
config.setTemplateLocation("conf/ruby/templates");
|
||||||
|
config.setStructureLocation("conf/ruby/structure");
|
||||||
|
config.setExceptionPackageName("com.wordnik.swagger.exception");
|
||||||
|
config.setAnnotationPackageName("com.wordnik.swagger.annotations");
|
||||||
|
|
||||||
|
config.setOutputDirectory(classOutputDir, "models", "resources");
|
||||||
|
|
||||||
|
//create ouput directories
|
||||||
|
FileUtil.createOutputDirectories(config.getModelClassLocation(), config.getClassFileExtension());
|
||||||
|
FileUtil.createOutputDirectories(config.getResourceClassLocation(), config.getClassFileExtension());
|
||||||
|
FileUtil.clearFolder(config.getModelClassLocation());
|
||||||
|
FileUtil.clearFolder(config.getResourceClassLocation());
|
||||||
|
FileUtil.clearFolder(config.getLibraryHome() + "/src/main/ruby/com/wordnik/swagger/runtime");
|
||||||
|
FileUtil.createOutputDirectories(config.getLibraryHome() + "/src/main/ruby/lib", "ruby");
|
||||||
|
FileUtil.copyDirectory(new File(config.getStructureLocation()), new File(classOutputDir));
|
||||||
|
|
||||||
|
config
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,6 @@ import java.util.List;
|
|||||||
* Time: 7:54 AM
|
* Time: 7:54 AM
|
||||||
*/
|
*/
|
||||||
public class EndpointOperation {
|
public class EndpointOperation {
|
||||||
|
|
||||||
public static String PARAM_TYPE_QUERY = "query";
|
public static String PARAM_TYPE_QUERY = "query";
|
||||||
public static String PARAM_TYPE_PATH = "path";
|
public static String PARAM_TYPE_PATH = "path";
|
||||||
public static String PARAM_TYPE_BODY = "body";
|
public static String PARAM_TYPE_BODY = "body";
|
||||||
@ -41,7 +40,9 @@ public class EndpointOperation {
|
|||||||
private static String API_KEY_PARAM_NAME = "api_key";
|
private static String API_KEY_PARAM_NAME = "api_key";
|
||||||
private static String FORMAT_PARAM_NAME = "format";
|
private static String FORMAT_PARAM_NAME = "format";
|
||||||
|
|
||||||
private static String AUTH_TOKEN_ARGUMENT_NAME = "authToken";
|
private static String AUTH_TOKEN_ARGUMENT_NAME = "authToken";
|
||||||
|
|
||||||
|
private static int ARG_COUNT_FOR_INPUT_MODEL = 4;
|
||||||
|
|
||||||
private String httpMethod;
|
private String httpMethod;
|
||||||
|
|
||||||
@ -64,6 +65,14 @@ public class EndpointOperation {
|
|||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
private List<ErrorResponse> errorResponses;
|
private List<ErrorResponse> errorResponses;
|
||||||
|
|
||||||
|
public static int getArgCountForInputModel(){
|
||||||
|
return ARG_COUNT_FOR_INPUT_MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setArgCountForInputModel(int argCount){
|
||||||
|
ARG_COUNT_FOR_INPUT_MODEL = argCount;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ErrorResponse> getErrorResponses() {
|
public List<ErrorResponse> getErrorResponses() {
|
||||||
return errorResponses;
|
return errorResponses;
|
||||||
@ -221,6 +230,8 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(AUTH_TOKEN_ARGUMENT_NAME);
|
anArgument.setName(AUTH_TOKEN_ARGUMENT_NAME);
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
}else if(modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_HEADER) &&
|
}else if(modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_HEADER) &&
|
||||||
modelField.getName().equals(API_KEY_PARAM_NAME)){
|
modelField.getName().equals(API_KEY_PARAM_NAME)){
|
||||||
@ -230,12 +241,16 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(true); // always true
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
pathParams.add(anArgument);
|
pathParams.add(anArgument);
|
||||||
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_QUERY)) {
|
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_QUERY)) {
|
||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
queryParams.add(anArgument);
|
queryParams.add(anArgument);
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_BODY)) {
|
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_BODY)) {
|
||||||
@ -245,6 +260,8 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(dataTypeMapper.getClassType(modelField.getDataType(), false));
|
anArgument.setDataType(dataTypeMapper.getClassType(modelField.getDataType(), false));
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
method.setPostObject(true);
|
method.setPostObject(true);
|
||||||
}
|
}
|
||||||
@ -259,7 +276,7 @@ public class EndpointOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check for number of arguments, if we have more than 4 then send the arguments as input object
|
//check for number of arguments, if we have more than 4 then send the arguments as input object
|
||||||
if(method.getArguments() != null && method.getArguments().size() > 4){
|
if(method.getArguments() != null && method.getArguments().size() > ARG_COUNT_FOR_INPUT_MODEL){
|
||||||
List<MethodArgument> arguments = new ArrayList<MethodArgument>();
|
List<MethodArgument> arguments = new ArrayList<MethodArgument>();
|
||||||
Model modelforMethodInput = new Model();
|
Model modelforMethodInput = new Model();
|
||||||
modelforMethodInput.setName(inputobjectName);
|
modelforMethodInput.setName(inputobjectName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user