From 92eb722cedc33e2e6f24bc32928459f9b0bb7246 Mon Sep 17 00:00:00 2001 From: Cliffano Subagio Date: Wed, 7 Sep 2016 00:25:39 +1000 Subject: [PATCH] [ruby] Add gemspec required_ruby_version setting. (#3718) * [ruby] Add gemspec required_ruby_version setting. * [ruby] Add gemspec required_ruby_version setting. * Add gemRequiredRubyVersion option to Ruby client code generator. --- .../codegen/languages/RubyClientCodegen.java | 13 +++++++++++++ .../src/main/resources/ruby/gemspec.mustache | 1 + .../codegen/options/RubyClientOptionsProvider.java | 2 ++ .../swagger/codegen/ruby/RubyClientOptionsTest.java | 2 ++ samples/client/petstore/ruby/README.md | 1 + samples/client/petstore/ruby/petstore.gemspec | 1 + 6 files changed, 20 insertions(+) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index 5ccdf19cbdb..1bcadeef9ef 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -30,6 +30,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { public static final String MODULE_NAME = "moduleName"; public static final String GEM_VERSION = "gemVersion"; public static final String GEM_LICENSE = "gemLicense"; + public static final String GEM_REQUIRED_RUBY_VERSION = "gemRequiredRubyVersion"; public static final String GEM_HOMEPAGE = "gemHomepage"; public static final String GEM_SUMMARY = "gemSummary"; public static final String GEM_DESCRIPTION = "gemDescription"; @@ -42,6 +43,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { protected String specFolder = "spec"; protected String libFolder = "lib"; protected String gemLicense = "Apache-2.0"; + protected String gemRequiredRubyVersion = ">= 1.9"; protected String gemHomepage = "http://swagger.io"; protected String gemSummary = "A ruby wrapper for the swagger APIs"; protected String gemDescription = "This gem maps to a swagger API"; @@ -143,6 +145,9 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { cliOptions.add(new CliOption(GEM_LICENSE, "gem license. "). defaultValue("Apache-2.0")); + cliOptions.add(new CliOption(GEM_REQUIRED_RUBY_VERSION, "gem required Ruby version. "). + defaultValue(">= 1.9")); + cliOptions.add(new CliOption(GEM_HOMEPAGE, "gem homepage. "). defaultValue("http://swagger.io")); @@ -203,6 +208,10 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { setGemLicense((String) additionalProperties.get(GEM_LICENSE)); } + if (additionalProperties.containsKey(GEM_REQUIRED_RUBY_VERSION)) { + setGemRequiredRubyVersion((String) additionalProperties.get(GEM_REQUIRED_RUBY_VERSION)); + } + if (additionalProperties.containsKey(GEM_HOMEPAGE)) { setGemHomepage((String) additionalProperties.get(GEM_HOMEPAGE)); } @@ -708,6 +717,10 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { this.gemLicense = gemLicense; } + public void setGemRequiredRubyVersion(String gemRequiredRubyVersion) { + this.gemRequiredRubyVersion = gemRequiredRubyVersion; + } + public void setGemHomepage(String gemHomepage) { this.gemHomepage = gemHomepage; } diff --git a/modules/swagger-codegen/src/main/resources/ruby/gemspec.mustache b/modules/swagger-codegen/src/main/resources/ruby/gemspec.mustache index 86d9a6e55d8..935fad7f61b 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/gemspec.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/gemspec.mustache @@ -17,6 +17,7 @@ Gem::Specification.new do |s| s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" s.license = "{{gemLicense}}{{^gemLicense}}{{{licenseInfo}}}{{^licenseInfo}}Apache 2.0{{/licenseInfo}}{{/gemLicense}}" + s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 1.9{{/gemRequiredRubyVersion}}" s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3' diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/RubyClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/RubyClientOptionsProvider.java index 55c81e6fdc4..34a36534a31 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/RubyClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/RubyClientOptionsProvider.java @@ -14,6 +14,7 @@ public class RubyClientOptionsProvider implements OptionsProvider { public static final String SORT_PARAMS_VALUE = "false"; public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; public static final String GEM_LICENSE_VALUE = "MIT"; + public static final String GEM_REQUIRED_RUBY_VERSION_VALUE = ">= 1.9"; public static final String GEM_HOMEPAGE_VALUE = "homepage"; public static final String GEM_SUMMARY_VALUE = "summary"; public static final String GEM_DESCRIPTION_VALUE = "description"; @@ -32,6 +33,7 @@ public class RubyClientOptionsProvider implements OptionsProvider { .put(RubyClientCodegen.MODULE_NAME, MODULE_NAME_VALUE) .put(RubyClientCodegen.GEM_VERSION, GEM_VERSION_VALUE) .put(RubyClientCodegen.GEM_LICENSE, GEM_LICENSE_VALUE) + .put(RubyClientCodegen.GEM_REQUIRED_RUBY_VERSION, GEM_REQUIRED_RUBY_VERSION_VALUE) .put(RubyClientCodegen.GEM_DESCRIPTION, GEM_DESCRIPTION_VALUE) .put(RubyClientCodegen.GEM_HOMEPAGE, GEM_HOMEPAGE_VALUE) .put(RubyClientCodegen.GEM_SUMMARY, GEM_SUMMARY_VALUE) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientOptionsTest.java index f61367e8220..9bf7eea4c94 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientOptionsTest.java @@ -34,6 +34,8 @@ public class RubyClientOptionsTest extends AbstractOptionsTest { times = 1; clientCodegen.setGemLicense(RubyClientOptionsProvider.GEM_LICENSE_VALUE); times = 1; + clientCodegen.setGemRequiredRubyVersion(RubyClientOptionsProvider.GEM_REQUIRED_RUBY_VERSION_VALUE); + times = 1; clientCodegen.setGemHomepage(RubyClientOptionsProvider.GEM_HOMEPAGE_VALUE); times = 1; clientCodegen.setGemDescription(RubyClientOptionsProvider.GEM_DESCRIPTION_VALUE); diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md index 188335045f6..1aa8be7831a 100644 --- a/samples/client/petstore/ruby/README.md +++ b/samples/client/petstore/ruby/README.md @@ -8,6 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/ - API version: 1.0.0 - Package version: 1.0.0 +- Build date: 2016-09-04T00:22:35.922+10:00 - Build package: class io.swagger.codegen.languages.RubyClientCodegen ## Installation diff --git a/samples/client/petstore/ruby/petstore.gemspec b/samples/client/petstore/ruby/petstore.gemspec index 4075ba0fc2d..9d4aa367b9c 100644 --- a/samples/client/petstore/ruby/petstore.gemspec +++ b/samples/client/petstore/ruby/petstore.gemspec @@ -36,6 +36,7 @@ Gem::Specification.new do |s| s.summary = "Swagger Petstore Ruby Gem" s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\" s.license = "Apache 2.0" + s.required_ruby_version = ">= 1.9" s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'