forked from loafle/openapi-generator-original
updated to make names friendly
This commit is contained in:
parent
a7156e6f00
commit
f37f284605
@ -14,17 +14,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.wordnik.swagger.codegen.BasicScalaGenerator
|
import com.wordnik.swagger.codegen.BasicRubyGenerator
|
||||||
|
|
||||||
import com.wordnik.swagger.core._
|
import com.wordnik.swagger.core._
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import scala.collection.mutable.{ HashMap, ListBuffer }
|
import scala.collection.mutable.{ HashMap, ListBuffer }
|
||||||
|
|
||||||
object SinatraServerGenerator extends BasicScalaGenerator {
|
object SinatraServerGenerator extends BasicRubyGenerator {
|
||||||
def main(args: Array[String]) = generateClient(args)
|
def main(args: Array[String]) = generateClient(args)
|
||||||
|
|
||||||
|
override def toApiName(name: String): String = {
|
||||||
|
name + "_api"
|
||||||
|
}
|
||||||
|
|
||||||
override def templateDir = "samples/server-generator/sinatra/templates"
|
override def templateDir = "samples/server-generator/sinatra/templates"
|
||||||
|
|
||||||
val outputFolder = "samples/server-generator/sinatra/output"
|
val outputFolder = "samples/server-generator/sinatra/output"
|
||||||
@ -45,8 +48,8 @@ object SinatraServerGenerator extends BasicScalaGenerator {
|
|||||||
override def supportingFiles = List(
|
override def supportingFiles = List(
|
||||||
("README.md", outputFolder, "README.md"),
|
("README.md", outputFolder, "README.md"),
|
||||||
("config.ru", outputFolder, "config.ru"),
|
("config.ru", outputFolder, "config.ru"),
|
||||||
("MyApp.rb", outputFolder, "MyApp.rb"),
|
("my_app.mustache", outputFolder, "my_app.rb"),
|
||||||
("lib/Swaggering.rb", outputFolder + File.separator + "lib", "Swaggering.rb"))
|
("lib/swaggering.rb", outputFolder + File.separator + "lib", "swaggering.rb"))
|
||||||
|
|
||||||
override def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
override def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
||||||
val mutable = scala.collection.mutable.Map() ++ m
|
val mutable = scala.collection.mutable.Map() ++ m
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
require './lib/swaggering'
|
|
||||||
|
|
||||||
# only need to extend if you want special configuration!
|
|
||||||
class MyApp < Swaggering
|
|
||||||
self.configure do |config|
|
|
||||||
config.api_version = '0.2'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require './lib/PetApi.rb'
|
|
||||||
require './lib/StoreApi.rb'
|
|
||||||
require './lib/UserApi.rb'
|
|
@ -1,2 +1,2 @@
|
|||||||
require './myapp'
|
require './my_app'
|
||||||
run MyApp
|
run MyApp
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
require 'json'
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/:petId', {
|
|
||||||
"resourcePath" => "/pet",
|
|
||||||
"summary" => "Find pet by ID",
|
|
||||||
"nickname" => "getPetById",
|
|
||||||
"responseClass" => "Pet",
|
|
||||||
"endpoint" => "/:petId",
|
|
||||||
"notes" => "Returns a pet based on ID",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "petId",
|
|
||||||
"description" => "ID of pet that needs to be fetched",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('post', '/', {
|
|
||||||
"resourcePath" => "/pet",
|
|
||||||
"summary" => "Add a new pet to the store",
|
|
||||||
"nickname" => "addPet",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "Pet object that needs to be added to the store",
|
|
||||||
"dataType" => "Pet",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('put', '/', {
|
|
||||||
"resourcePath" => "/pet",
|
|
||||||
"summary" => "Update an existing pet",
|
|
||||||
"nickname" => "updatePet",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "Pet object that needs to be updated in the store",
|
|
||||||
"dataType" => "Pet",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/findByStatus', {
|
|
||||||
"resourcePath" => "/pet",
|
|
||||||
"summary" => "Finds Pets by status",
|
|
||||||
"nickname" => "findPetsByStatus",
|
|
||||||
"responseClass" => "List[Pet]",
|
|
||||||
"endpoint" => "/findByStatus",
|
|
||||||
"notes" => "Multiple status values can be provided with comma seperated strings",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "status",
|
|
||||||
"description" => "Status values that need to be considered for filter",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "query",
|
|
||||||
"allowMultiple" => true,
|
|
||||||
"allowableValues" => "LIST[available,pending,sold]",
|
|
||||||
"defaultValue" => "available"},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/findByTags', {
|
|
||||||
"resourcePath" => "/pet",
|
|
||||||
"summary" => "Finds Pets by tags",
|
|
||||||
"nickname" => "findPetsByTags",
|
|
||||||
"responseClass" => "List[Pet]",
|
|
||||||
"endpoint" => "/findByTags",
|
|
||||||
"notes" => "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "tags",
|
|
||||||
"description" => "Tags to filter by",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "query",
|
|
||||||
"allowMultiple" => true,
|
|
||||||
"allowableValues" => "",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
require 'json'
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/order/:orderId', {
|
|
||||||
"resourcePath" => "/store",
|
|
||||||
"summary" => "Find purchase order by ID",
|
|
||||||
"nickname" => "getOrderById",
|
|
||||||
"responseClass" => "Order",
|
|
||||||
"endpoint" => "/order/:orderId",
|
|
||||||
"notes" => "For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "orderId",
|
|
||||||
"description" => "ID of pet that needs to be fetched",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('delete', '/order/:orderId', {
|
|
||||||
"resourcePath" => "/store",
|
|
||||||
"summary" => "Delete purchase order by ID",
|
|
||||||
"nickname" => "deleteOrder",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/order/:orderId",
|
|
||||||
"notes" => "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "orderId",
|
|
||||||
"description" => "ID of the order that needs to be deleted",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('post', '/order', {
|
|
||||||
"resourcePath" => "/store",
|
|
||||||
"summary" => "Place an order for a pet",
|
|
||||||
"nickname" => "placeOrder",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/order",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "order placed for purchasing the pet",
|
|
||||||
"dataType" => "Order",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
@ -1,181 +0,0 @@
|
|||||||
require 'json'
|
|
||||||
|
|
||||||
MyApp.add_route('post', '/createWithArray', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Creates list of users with given input array",
|
|
||||||
"nickname" => "createUsersWithArrayInput",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/createWithArray",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "List of user object",
|
|
||||||
"dataType" => "Array[User]",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('post', '/', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Create user",
|
|
||||||
"nickname" => "createUser",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/",
|
|
||||||
"notes" => "This can only be done by the logged in user.",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "Created user object",
|
|
||||||
"dataType" => "User",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('post', '/createWithList', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Creates list of users with given list input",
|
|
||||||
"nickname" => "createUsersWithListInput",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/createWithList",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "List of user object",
|
|
||||||
"dataType" => "List[User]",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('put', '/:username', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Updated user",
|
|
||||||
"nickname" => "updateUser",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/:username",
|
|
||||||
"notes" => "This can only be done by the logged in user.",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "username",
|
|
||||||
"description" => "name that need to be deleted",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name" => "body",
|
|
||||||
"description" => "Updated user object",
|
|
||||||
"dataType" => "User",
|
|
||||||
"paramType" => "body",
|
|
||||||
}
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('delete', '/:username', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Delete user",
|
|
||||||
"nickname" => "deleteUser",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/:username",
|
|
||||||
"notes" => "This can only be done by the logged in user.",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "username",
|
|
||||||
"description" => "The name that needs to be deleted",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/:username', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Get user by user name",
|
|
||||||
"nickname" => "getUserByName",
|
|
||||||
"responseClass" => "User",
|
|
||||||
"endpoint" => "/:username",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "username",
|
|
||||||
"description" => "The name that needs to be fetched. Use user1 for testing.",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/login', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Logs user into the system",
|
|
||||||
"nickname" => "loginUser",
|
|
||||||
"responseClass" => "String",
|
|
||||||
"endpoint" => "/login",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
{
|
|
||||||
"name" => "username",
|
|
||||||
"description" => "The user name for login",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "query",
|
|
||||||
"allowMultiple" => false,
|
|
||||||
"allowableValues" => "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name" => "password",
|
|
||||||
"description" => "The password for login in clear text",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "query",
|
|
||||||
"allowMultiple" => false,
|
|
||||||
"allowableValues" => "",
|
|
||||||
},
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
MyApp.add_route('get', '/logout', {
|
|
||||||
"resourcePath" => "/user",
|
|
||||||
"summary" => "Logs out current logged in user session",
|
|
||||||
"nickname" => "logoutUser",
|
|
||||||
"responseClass" => "void",
|
|
||||||
"endpoint" => "/logout",
|
|
||||||
"notes" => "",
|
|
||||||
"parameters" => [
|
|
||||||
]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
require './lib/swaggering'
|
|
||||||
|
|
||||||
# only need to extend if you want special configuration!
|
|
||||||
class MyApp < Swaggering
|
|
||||||
self.configure do |config|
|
|
||||||
config.api_version = '0.2'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require './lib/PetApi.rb'
|
|
||||||
require './lib/StoreApi.rb'
|
|
||||||
require './lib/UserApi.rb'
|
|
@ -1,2 +1,2 @@
|
|||||||
require './myapp'
|
require './my_app'
|
||||||
run MyApp
|
run MyApp
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
require 'json'
|
|
||||||
require './lib/swaggering'
|
|
||||||
require 'sinatra/cross_origin'
|
|
||||||
|
|
||||||
configure do
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# only need to extend if you want special configuration!
|
|
||||||
class MyApp < Swaggering
|
|
||||||
self.configure do |config|
|
|
||||||
config.api_version = '0.2'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# add all your routes
|
|
||||||
{{#apis}}
|
|
||||||
{{#operations}}
|
|
||||||
MyApp.add_route('{{httpMethod}}', '{{path}}', {
|
|
||||||
"resourcePath" => "{{resourcePath}}",
|
|
||||||
"summary" => "{{{summary}}}",
|
|
||||||
"nickname" => "{{nickname}}",
|
|
||||||
"responseClass" => "{{responseClass}}",
|
|
||||||
"endpoint" => "{{name}}",
|
|
||||||
"notes" => "{{{notes}}}",
|
|
||||||
"parameters" => [{
|
|
||||||
"name" => "status",
|
|
||||||
"description" => "Status values that need to be considered for filter",
|
|
||||||
"dataType" => "string",
|
|
||||||
"paramType" => "path",
|
|
||||||
"allowMultiple" => true,
|
|
||||||
"allowableValues" => "LIST[available,pending,sold]",
|
|
||||||
"defaultValue" => "available"}]}) do
|
|
||||||
cross_origin
|
|
||||||
# the guts live here
|
|
||||||
|
|
||||||
{"message" => "yes, it worked"}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
{{/operations}}
|
|
||||||
{{/apis}}
|
|
Loading…
x
Reference in New Issue
Block a user