From 7cd8d0a1acf3fe955d942a4847f84aeafc059ac3 Mon Sep 17 00:00:00 2001 From: xhh Date: Wed, 8 Apr 2015 21:18:12 +0800 Subject: [PATCH 1/4] Restructure gemspec related files to ease importing the files --- samples/client/petstore/ruby/Gemfile.lock | 4 ++-- samples/client/petstore/ruby/lib/swagger-client.rb | 5 +++++ samples/client/petstore/ruby/spec/pet_spec.rb | 3 ++- samples/client/petstore/ruby/spec/spec_helper.rb | 7 +------ .../ruby/{swagger.gemspec => swagger-client.gemspec} | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 samples/client/petstore/ruby/lib/swagger-client.rb rename samples/client/petstore/ruby/{swagger.gemspec => swagger-client.gemspec} (90%) diff --git a/samples/client/petstore/ruby/Gemfile.lock b/samples/client/petstore/ruby/Gemfile.lock index 2fb53785500..232facf4677 100644 --- a/samples/client/petstore/ruby/Gemfile.lock +++ b/samples/client/petstore/ruby/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - swagger (4.06.08) + swagger-client (4.06.08) addressable (>= 2.2.4) json (>= 1.4.6) typhoeus (>= 0.2.1) @@ -56,6 +56,6 @@ DEPENDENCIES autotest-growl autotest-rails-pure rspec (>= 2.5.0) - swagger! + swagger-client! vcr (>= 1.5.1) webmock (>= 1.6.2) diff --git a/samples/client/petstore/ruby/lib/swagger-client.rb b/samples/client/petstore/ruby/lib/swagger-client.rb new file mode 100644 index 00000000000..b13f83b1dbc --- /dev/null +++ b/samples/client/petstore/ruby/lib/swagger-client.rb @@ -0,0 +1,5 @@ +require 'monkey' +require 'swagger' + +Dir[File.join(File.dirname(__FILE__), "../lib/*.rb")].each {|file| require file if file !~ /swagger-client\.rb\z/ } +Dir[File.join(File.dirname(__FILE__), "../models/*.rb")].each {|file| require file } diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 2a715f8b8eb..7a16b4d06d9 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -12,8 +12,9 @@ describe "Pet" do describe "pet methods" do it "should fetch a pet object" do pet = PetApi.getPetById(5) + pet.should be_a(Pet) pet.id.should == 5 - pet.name.should == "Dog 2" + pet.name.should == "panda" end it "should find pets by status" do diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index dbdcdeda579..f5ea626e9b8 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -1,17 +1,12 @@ require 'rubygems' require 'bundler/setup' -require 'monkey' -require 'swagger' +require 'swagger-client' require 'vcr' require 'typhoeus' require 'json' require 'yaml' require 'rspec' -Dir[File.join(File.dirname(__FILE__), "../lib/*.rb")].each {|file| require file } -Dir[File.join(File.dirname(__FILE__), "../models/*.rb")].each {|file| require file } -Dir[File.join(File.dirname(__FILE__), "../resources/*.rb")].each {|file| require file } - RSpec.configure do |config| # some (optional) config here config.expect_with :rspec do |c| diff --git a/samples/client/petstore/ruby/swagger.gemspec b/samples/client/petstore/ruby/swagger-client.gemspec similarity index 90% rename from samples/client/petstore/ruby/swagger.gemspec rename to samples/client/petstore/ruby/swagger-client.gemspec index 61bab334b3b..bbff5f95f6b 100644 --- a/samples/client/petstore/ruby/swagger.gemspec +++ b/samples/client/petstore/ruby/swagger-client.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) require "swagger/version" Gem::Specification.new do |s| - s.name = "swagger" + s.name = "swagger-client" s.version = Swagger::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Zeke Sikelianos", "Tony Tam"] @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = %q{A ruby wrapper for the swagger APIs} s.description = %q{This gem maps to a swagger API} - s.rubyforge_project = "swagger" + s.rubyforge_project = "swagger-client" s.add_dependency 'typhoeus', '>=0.2.1' s.add_dependency 'addressable', '>=2.2.4' @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '>=2.5.0' s.add_development_dependency 'vcr', '>=1.5.1' s.add_development_dependency 'webmock', '>=1.6.2' - s.add_development_dependency 'autotest' + s.add_development_dependency 'autotest' s.add_development_dependency 'autotest-rails-pure' s.add_development_dependency 'autotest-growl' s.add_development_dependency 'autotest-fsevent' From 02fa04aec88a7bd3139b05e0d797cde8ab8ec109 Mon Sep 17 00:00:00 2001 From: xhh Date: Wed, 8 Apr 2015 21:25:14 +0800 Subject: [PATCH 2/4] Generate gemspec for Ruby client --- .../codegen/languages/RubyClientCodegen.java | 2 ++ .../ruby/swagger-client.gemspec.mustache | 33 +++++++++++++++++++ .../resources/ruby/swagger-client.mustache | 5 +++ 3 files changed, 40 insertions(+) create mode 100644 modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache create mode 100644 modules/swagger-codegen/src/main/resources/ruby/swagger-client.mustache diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java index f2f0f00df87..5decf61d2c0 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java @@ -64,6 +64,8 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("List", "array"); typeMapping.put("map", "map"); + supportingFiles.add(new SupportingFile("swagger-client.gemspec.mustache", "", "swagger-client.gemspec")); + supportingFiles.add(new SupportingFile("swagger-client.mustache", "", "lib/swagger-client.rb")); supportingFiles.add(new SupportingFile("swagger.mustache", "", "lib/swagger.rb")); supportingFiles.add(new SupportingFile("monkey.mustache", "", "lib/monkey.rb")); supportingFiles.add(new SupportingFile("swagger/request.mustache", "", "lib/swagger/request.rb")); diff --git a/modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache new file mode 100644 index 00000000000..c002e581b8b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "swagger/version" + +Gem::Specification.new do |s| + s.name = "{{artifactId}}" + s.version = Swagger::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["Zeke Sikelianos", "Tony Tam"] + s.email = ["zeke@wordnik.com", "tony@wordnik.com"] + s.homepage = "http://developer.wordnik.com" + s.summary = %q{A ruby wrapper for the swagger APIs} + s.description = %q{This gem maps to a swagger API} + + s.rubyforge_project = "{{artifactId}}" + + s.add_dependency 'typhoeus', '>=0.2.1' + s.add_dependency 'addressable', '>=2.2.4' + s.add_dependency 'json', '>=1.4.6' + + s.add_development_dependency 'rspec', '>=2.5.0' + s.add_development_dependency 'vcr', '>=1.5.1' + s.add_development_dependency 'webmock', '>=1.6.2' + s.add_development_dependency 'autotest' + s.add_development_dependency 'autotest-rails-pure' + s.add_development_dependency 'autotest-growl' + s.add_development_dependency 'autotest-fsevent' + + s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? } + s.test_files = `find spec/*`.split("\n") + s.executables = [] + s.require_paths = ["lib"] +end diff --git a/modules/swagger-codegen/src/main/resources/ruby/swagger-client.mustache b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.mustache new file mode 100644 index 00000000000..b13f83b1dbc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.mustache @@ -0,0 +1,5 @@ +require 'monkey' +require 'swagger' + +Dir[File.join(File.dirname(__FILE__), "../lib/*.rb")].each {|file| require file if file !~ /swagger-client\.rb\z/ } +Dir[File.join(File.dirname(__FILE__), "../models/*.rb")].each {|file| require file } From 817a74d4df12e1e4d2b035ea1328fecfe3e51833 Mon Sep 17 00:00:00 2001 From: xhh Date: Thu, 9 Apr 2015 11:32:10 +0800 Subject: [PATCH 3/4] Add README.md file containing instructions on Ruby petstore sample --- samples/client/petstore/ruby/README.md | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 samples/client/petstore/ruby/README.md diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md new file mode 100644 index 00000000000..29a7ce844ce --- /dev/null +++ b/samples/client/petstore/ruby/README.md @@ -0,0 +1,57 @@ +## Installation + +### Build a gem + +You can build the generated client into a gem: + +```shell +gem build swagger-client.gemspec +``` + +Then you can either install the gem: + +```shell +gem install ./swagger-client-4.06.08.gem +``` + +or publish the gem to a gem server like [RubyGems](https://rubygems.org/). + +Finally add this to your Gemfile: + + gem 'swagger-client', '~> 4.06.08' + +### Host as a git repository + +You can also choose to host the generated client as a git repository, e.g. on github: +https://github.com/xhh/swagger-petstore-ruby + +Then you can reference it in Gemfile: + + gem 'swagger-client', :git => 'https://github.com/xhh/swagger-petstore-ruby.git' + +### Use without installation + +You can also use the client directly like this: + +```shell +ruby -Ilib script.rb +``` + +## Configuration + +```ruby +require 'swagger-client' + +Swagger.configure do |config| + config.api_key = 'special-key' + config.host = 'petstore.swagger.io' + config.base_path = '/v2' +end +``` + +## Getting Started + +```ruby +pet = PetApi.getPetById(5) +puts pet.to_body +``` From e9c5c1434b239e5c2d5c8efba9dd30abe593fd3c Mon Sep 17 00:00:00 2001 From: xhh Date: Thu, 9 Apr 2015 11:37:48 +0800 Subject: [PATCH 4/4] Fix spec --- samples/client/petstore/ruby/spec/pet_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 7a16b4d06d9..0ea0a5dcd32 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -23,7 +23,7 @@ describe "Pet" do end it "should not find a pet with invalid status" do - pets = PetApi.findPetsByStatus('dead') + pets = PetApi.findPetsByStatus('invalid-status') pets.length.should == 0 end