From a4c9e26018b61069294607bf6bb731545bbe3a95 Mon Sep 17 00:00:00 2001 From: fehguy Date: Fri, 7 Sep 2012 07:39:23 -0700 Subject: [PATCH 1/4] Update samples/server-generator/sinatra/output/README.md --- samples/server-generator/sinatra/output/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/server-generator/sinatra/output/README.md b/samples/server-generator/sinatra/output/README.md index beec4407438..e09f82c3a79 100644 --- a/samples/server-generator/sinatra/output/README.md +++ b/samples/server-generator/sinatra/output/README.md @@ -17,7 +17,7 @@ sinatra-cross_origin This sample was generated with the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. ``` -rackup -p 4567 examples/config.ru +rackup -p 4567 ``` In your [swagger ui](https://github.com/wordnik/swagger-ui), put in the following URL: From 8d79437c8dd12b835bd60629a6a38302210bdcc4 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 7 Sep 2012 14:13:46 -0700 Subject: [PATCH 2/4] added readme --- samples/server-generator/sinatra/README.md | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 samples/server-generator/sinatra/README.md diff --git a/samples/server-generator/sinatra/README.md b/samples/server-generator/sinatra/README.md new file mode 100644 index 00000000000..8dd5cff2936 --- /dev/null +++ b/samples/server-generator/sinatra/README.md @@ -0,0 +1,64 @@ +# Swagger generated server + +## Overview +Using the swagger-codegen, you can not only generate clients but servers as well! The same spec can be used to drive your +development both ways. This is an example of generating a server for `node.js`. + +### Prerequisites +You need the following installed and available in your $PATH: + +
  • - Scala 2.9.1 [available here](http://www.scala-lang.org) + +You also need to add scala binary to your PATH. + +### Generating a server +You first need to build the `swagger-codegen` project--this is done by running this command at the root of the swagger-codegen project: + +``` +mvn package +``` + +You can now generate a server from any valid[**](https://github.com/wordnik/swagger-codegen/blob/master/README.md#validating-your-swagger-spec) swagger spec: + +``` +./bin/runscala.sh samples/server-generator/sinatra/SinatraServerGenerator.scala http://petstore.swagger.wordnik.com/api/resources.json special-key +``` + +After executing this script, you will have an output directory with the server-generated files: + +``` +$ cd samples/server-generator/sinatra/output +$ find . -type f +./config.ru +./Gemfile +./Gemfile.lock +./lib/pet_api.rb +./lib/store_api.rb +./lib/swaggering.rb +./lib/user_api.rb +./my_app.rb +./README.md +``` + +To run the server, cd to the `samples/server-generator/sinatra/output` folder and run: + +``` +rackup -p 4567 +``` + +You can now load the swagger-ui against `http://localhost:4567/resources.json`. Of course this isn't a fully +runnable server! You have to add the logic in the lib/*.rb files. But that's the easy part. + + +### Making it your own +Running the sample is easy, but how about making your own server? Easy! Just modify the `samples/server-generator/sinatra/SinatraServerGenerator.scala` file. + +Don't like the templates? Don't worry, we're not offended! They're [mustache](http://mustache.github.com/) templates and are easy to modify. +Take a look at the sample templates here: + +
  • - Generator for your api classes: [api.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/sinatra/templates/api.mustache) + +
  • - The main class to run your server: [my_app.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/my_app.mustache) + + +Sound easy? It is! From 2647f96c81c4c960c4801077f6941efa85782c69 Mon Sep 17 00:00:00 2001 From: fehguy Date: Fri, 7 Sep 2012 14:17:06 -0700 Subject: [PATCH 3/4] Update samples/server-generator/sinatra/README.md --- samples/server-generator/sinatra/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/server-generator/sinatra/README.md b/samples/server-generator/sinatra/README.md index 8dd5cff2936..764c7367345 100644 --- a/samples/server-generator/sinatra/README.md +++ b/samples/server-generator/sinatra/README.md @@ -58,7 +58,7 @@ Take a look at the sample templates here:
  • - Generator for your api classes: [api.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/sinatra/templates/api.mustache) -
  • - The main class to run your server: [my_app.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/my_app.mustache) +
  • - The main class to run your server: [my_app.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/sinatra/templates/my_app.mustache) Sound easy? It is! From 6829014393446d7eb45250f4297ad45ae46b8722 Mon Sep 17 00:00:00 2001 From: fehguy Date: Fri, 7 Sep 2012 14:18:04 -0700 Subject: [PATCH 4/4] Update samples/server-generator/scalatra/README.md --- samples/server-generator/scalatra/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/server-generator/scalatra/README.md b/samples/server-generator/scalatra/README.md index 7a7c97ca7ea..39361b3ab0c 100644 --- a/samples/server-generator/scalatra/README.md +++ b/samples/server-generator/scalatra/README.md @@ -47,7 +47,7 @@ $ find -type f ``` -To run the server, cd to the `samples/server-generator/node/output` folder and run: +To run the server, cd to the `samples/server-generator/scalatra/output` folder and run: ``` sbt run @@ -67,7 +67,7 @@ Take a look at the sample templates here:
  • - Generator for your models: [model.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/scalatra/templates/model.mustache) -
  • - The main class to run your server: [ServletApp.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/node/templates/ServletApp.mustache) +
  • - The main class to run your server: [ServletApp.mustache](https://github.com/wordnik/swagger-codegen/blob/master/samples/server-generator/scalatra/templates/ServletApp.mustache) Sound easy? It is!