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/samples/client/petstore/ruby/swagger.gemspec b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache similarity index 90% rename from samples/client/petstore/ruby/swagger.gemspec rename to modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache index 61bab334b3b..c002e581b8b 100644 --- a/samples/client/petstore/ruby/swagger.gemspec +++ b/modules/swagger-codegen/src/main/resources/ruby/swagger-client.gemspec.mustache @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) require "swagger/version" Gem::Specification.new do |s| - s.name = "swagger" + s.name = "{{artifactId}}" 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 = "{{artifactId}}" 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' 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 } 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/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 +``` 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..0ea0a5dcd32 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 @@ -22,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 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-client.gemspec b/samples/client/petstore/ruby/swagger-client.gemspec new file mode 100644 index 00000000000..bbff5f95f6b --- /dev/null +++ b/samples/client/petstore/ruby/swagger-client.gemspec @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "swagger/version" + +Gem::Specification.new do |s| + s.name = "swagger-client" + 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 = "swagger-client" + + 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