diff --git a/conf/ruby/sample/build.xml b/conf/ruby/sample/build.xml new file mode 100644 index 00000000000..b482a4eddb7 --- /dev/null +++ b/conf/ruby/sample/build.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/ruby/sample/ivy.xml b/conf/ruby/sample/ivy.xml new file mode 100644 index 00000000000..b2573f73d69 --- /dev/null +++ b/conf/ruby/sample/ivy.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/ruby/sample/ivysettings.xml b/conf/ruby/sample/ivysettings.xml new file mode 100644 index 00000000000..ea8e09b9f5b --- /dev/null +++ b/conf/ruby/sample/ivysettings.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/conf/ruby/sample/java_code_gen_conf.json b/conf/ruby/sample/java_code_gen_conf.json new file mode 100644 index 00000000000..74db34b345c --- /dev/null +++ b/conf/ruby/sample/java_code_gen_conf.json @@ -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" +} diff --git a/conf/ruby/sample/lib-test-data.json b/conf/ruby/sample/lib-test-data.json new file mode 100644 index 00000000000..24d529e981d --- /dev/null +++ b/conf/ruby/sample/lib-test-data.json @@ -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 + } + ] +} diff --git a/conf/ruby/sample/lib-test-script.json b/conf/ruby/sample/lib-test-script.json new file mode 100644 index 00000000000..7953c939cfb --- /dev/null +++ b/conf/ruby/sample/lib-test-script.json @@ -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" + } + ] + } + ] + } + ] +} + + + + + \ No newline at end of file diff --git a/conf/ruby/structure/swagger.rb b/conf/ruby/structure/swagger.rb new file mode 100644 index 00000000000..5995bad5c15 --- /dev/null +++ b/conf/ruby/structure/swagger.rb @@ -0,0 +1 @@ +# nothing to see yet \ No newline at end of file diff --git a/conf/ruby/templates/EnumObject.st b/conf/ruby/templates/EnumObject.st new file mode 100644 index 00000000000..545ba15eae0 --- /dev/null +++ b/conf/ruby/templates/EnumObject.st @@ -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"$ +} diff --git a/conf/ruby/templates/ModelObject.st b/conf/ruby/templates/ModelObject.st new file mode 100644 index 00000000000..435bb450f5a --- /dev/null +++ b/conf/ruby/templates/ModelObject.st @@ -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 \ No newline at end of file diff --git a/conf/ruby/templates/ResourceObject.st b/conf/ruby/templates/ResourceObject.st new file mode 100644 index 00000000000..e69fea3f6c2 --- /dev/null +++ b/conf/ruby/templates/ResourceObject.st @@ -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 + +}$ diff --git a/conf/ruby/templates/VersionChecker.st b/conf/ruby/templates/VersionChecker.st new file mode 100644 index 00000000000..134fc8e0a2c --- /dev/null +++ b/conf/ruby/templates/VersionChecker.st @@ -0,0 +1,5 @@ +module $resource$ + def get_compatible_version(*args) + '$apiVersion$' + end + \ No newline at end of file