mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 13:29:13 +00:00
Ruby client faraday (#3405)
* WIP: add faraday support to Ruby client * update samples * bin/console * https only * ruby-faraday: Add a gemspec template for faraday * Add a test for ruby-faraday client options * Remove Gemfile.lock from ruby-client-faraday * Implement faraday client * Problem: can't use Faraday library for ruby clients Solution: add support for Faraday library This patch builds on the work started by @meganemura * Problem: Faraday is set as default library Solution: Make Typhoeus default This patch also updates the api_client template for Faraday to include query params with requests.
This commit is contained in:
committed by
William Cheng
parent
f90f214121
commit
bcc3a9ecf7
@@ -46,6 +46,8 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
public static final String GEM_DESCRIPTION = "gemDescription";
|
||||
public static final String GEM_AUTHOR = "gemAuthor";
|
||||
public static final String GEM_AUTHOR_EMAIL = "gemAuthorEmail";
|
||||
public static final String FARADAY = "faraday";
|
||||
public static final String TYPHOEUS = "typhoeus";
|
||||
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
@@ -54,8 +56,8 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
protected String libFolder = "lib";
|
||||
protected String gemLicense = "unlicense";
|
||||
protected String gemRequiredRubyVersion = ">= 1.9";
|
||||
protected String gemHomepage = "http://org.openapitools";
|
||||
protected String gemSummary = "A ruby wrapper for the REST APIs";
|
||||
protected String gemHomepage = "https://openapitools.org";
|
||||
protected String gemSummary = "A Ruby SDK for the REST API";
|
||||
protected String gemDescription = "This gem maps to a REST API";
|
||||
protected String gemAuthor = "";
|
||||
protected String gemAuthorEmail = "";
|
||||
@@ -141,6 +143,15 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).
|
||||
defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
supportedLibraries.put(FARADAY, "Faraday (https://github.com/lostisland/faraday) (Beta support)");
|
||||
supportedLibraries.put(TYPHOEUS, "Typhoeus >= 1.0.1 (https://github.com/typhoeus/typhoeus)");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "HTTP library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
// set TYPHOEUS as the default
|
||||
libraryOption.setDefault(TYPHOEUS);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(TYPHOEUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,10 +220,8 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
setModelPackage("models");
|
||||
setApiPackage("api");
|
||||
|
||||
supportingFiles.add(new SupportingFile("gemspec.mustache", "", gemName + ".gemspec"));
|
||||
supportingFiles.add(new SupportingFile("gem.mustache", libFolder, gemName + ".rb"));
|
||||
String gemFolder = libFolder + File.separator + gemName;
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", gemFolder, "api_client.rb"));
|
||||
supportingFiles.add(new SupportingFile("api_error.mustache", gemFolder, "api_error.rb"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb"));
|
||||
supportingFiles.add(new SupportingFile("version.mustache", gemFolder, "version.rb"));
|
||||
@@ -221,10 +230,20 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("Rakefile.mustache", "", "Rakefile"));
|
||||
supportingFiles.add(new SupportingFile("Gemfile.mustache", "", "Gemfile"));
|
||||
supportingFiles.add(new SupportingFile("Gemfile.lock.mustache", "", "Gemfile.lock"));
|
||||
supportingFiles.add(new SupportingFile("rubocop.mustache", "", ".rubocop.yml"));
|
||||
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
||||
|
||||
if (TYPHOEUS.equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", gemFolder, "api_client.rb"));
|
||||
supportingFiles.add(new SupportingFile("gemspec.mustache", "", gemName + ".gemspec"));
|
||||
supportingFiles.add(new SupportingFile("Gemfile.lock.mustache", "", "Gemfile.lock"));
|
||||
} else if (FARADAY.equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("faraday_api_client.mustache", gemFolder, "api_client.rb"));
|
||||
supportingFiles.add(new SupportingFile("faraday_gemspec.mustache", "", gemName + ".gemspec"));
|
||||
} else {
|
||||
throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only faraday, typhoeus are supported.");
|
||||
}
|
||||
|
||||
// test files should not be overwritten
|
||||
writeOptional(outputFolder, new SupportingFile("rspec.mustache", "", ".rspec"));
|
||||
writeOptional(outputFolder, new SupportingFile("spec_helper.mustache", specFolder, "spec_helper.rb"));
|
||||
|
||||
Reference in New Issue
Block a user