Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 43 additions & 0 deletions bin/openapi3/ruby-client-faraday-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# purge lib/doc folder
echo "purge ruby petstore lib, docs folder"
rm -Rf samples/openapi3/client/petstore/ruby-faraday/lib
rm -Rf samples/openapi3/client/petstore/ruby-faraday/docs

# purge test files other than integration test
# NOTE: spec/custom/*.rb and spec/petstore_helper.rb are not generated files
echo "purge ruby petstore spec"
find samples/openapi3/client/petstore/ruby-faraday/spec -type d -not -name spec -not -name custom | xargs rm -Rf
find samples/openapi3/client/petstore/ruby-faraday/spec -type f -not -name petstore_helper.rb -not -iwholename '*/spec/custom/*' | xargs rm -Rf

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/ruby-client -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ruby -c bin/openapi3/ruby-petstore-faraday.json -o samples/openapi3/client/petstore/ruby-faraday --additional-properties skipFormModel=true $@"

java $JAVA_OPTS -jar $executable $ags
6 changes: 6 additions & 0 deletions bin/openapi3/ruby-petstore-faraday.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"gemName": "petstore",
"moduleName": "Petstore",
"library": "faraday",
"gemVersion": "1.0.0"
}
1 change: 1 addition & 0 deletions bin/ruby-petstore-faraday.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"gemName": "petstore",
"moduleName": "Petstore",
"library": "faraday",
"gemVersion": "1.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("Gemfile.mustache", "", "Gemfile"));
supportingFiles.add(new SupportingFile("rubocop.mustache", "", ".rubocop.yml"));
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("gemspec.mustache", "", gemName + ".gemspec"));

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"));
additionalProperties.put("isFaraday", Boolean.TRUE);
} else {
throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only faraday, typhoeus are supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe {{moduleName}}::ApiClient do
end
end

{{^isFaraday}}
describe 'params_encoding in #build_request' do
let(:config) { {{moduleName}}::Configuration.new }
let(:api_client) { {{moduleName}}::ApiClient.new(config) }
Expand Down Expand Up @@ -81,6 +82,7 @@ describe {{moduleName}}::ApiClient do
end
end

{{/isFaraday}}
describe '#deserialize' do
it "handles Array<Integer>" do
api_client = {{moduleName}}::ApiClient.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ module {{moduleName}}
connection = Faraday.new(:url => config.base_url) do |conn|
conn.basic_auth(config.username, config.password)
if opts[:header_params]["Content-Type"] == "multipart/form-data"
conn.request :multipart
conn.request :url_encoded
conn.request :multipart
conn.request :url_encoded
end
conn.adapter(Faraday.default_adapter)
end
begin
response = connection.public_send(http_method.to_sym.downcase) do |req|
build_request(http_method, path, req, opts)
end
response = connection.public_send(http_method.to_sym.downcase) do |req|
build_request(http_method, path, req, opts)
end

if @config.debugging
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
end
if @config.debugging
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
end

unless response.success?
if response.status == 0
# Errors from libcurl will be made visible here
fail ApiError.new(:code => 0,
:message => response.return_message)
else
fail ApiError.new(:code => response.status,
:response_headers => response.headers,
:response_body => response.body),
response.reason_phrase
end
unless response.success?
if response.status == 0
# Errors from libcurl will be made visible here
fail ApiError.new(:code => 0,
:message => response.return_message)
else
fail ApiError.new(:code => response.status,
:response_headers => response.headers,
:response_body => response.body),
response.reason_phrase
end
end
rescue Faraday::TimeoutError
fail ApiError.new('Connection timed out')
fail ApiError.new('Connection timed out')
end

if opts[:return_type]
Expand Down Expand Up @@ -126,7 +126,7 @@ module {{moduleName}}
end
request.headers = header_params
request.body = req_body
request.url path
request.url url
request.params = query_params
download_file(request) if opts[:return_type] == 'File'
request
Expand Down Expand Up @@ -277,13 +277,15 @@ module {{moduleName}}
# @return [String] HTTP body data in the form of string
def build_request_body(header_params, form_params, body)
# http form
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
header_params['Content-Type'] == 'multipart/form-data'
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
data = URI.encode_www_form(form_params)
elsif header_params['Content-Type'] == 'multipart/form-data'
data = {}
form_params.each do |key, value|
case value
when ::File, ::Tempfile
data[key] = Faraday::UploadIO.new(value.path, '')
# TODO hardcode to application/octet-stream, need better way to detect content type
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
when ::Array, nil
# let Faraday handle Array and nil parameters
data[key] = value
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ Gem::Specification.new do |s|
{{/gemLicense}}
s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 1.9{{/gemRequiredRubyVersion}}"

{{#isFaraday}}
s.add_runtime_dependency 'faraday', '>= 0.14.0'
{{/isFaraday}}
{{^isFaraday}}
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
{{/isFaraday}}
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'

s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.3-SNAPSHOT
4.1.0-SNAPSHOT
4 changes: 2 additions & 2 deletions samples/client/petstore/ruby-faraday/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Expand Down Expand Up @@ -46,7 +46,7 @@ Layout/EmptyLinesAroundMethodBody:
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstParameterIndentation:
Layout/IndentFirstArgument:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/ruby-faraday/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: ruby
cache: bundler
rvm:
- 2.3
- 2.4
- 2.5
script:
- bundle install --path vendor/bundle
- bundle exec rspec
- gem build petstore.gemspec
- gem install ./petstore-1.0.0.gem
1 change: 1 addition & 0 deletions samples/client/petstore/ruby-faraday/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gemspec
group :development, :test do
gem 'rake', '~> 12.0.0'
gem 'pry-byebug'
gem 'rubocop', '~> 0.66.0'
end
24 changes: 20 additions & 4 deletions samples/client/petstore/ruby-faraday/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Then either install the gem locally:
```shell
gem install ./petstore-1.0.0.gem
```

(for development, run `gem install --dev ./petstore-1.0.0.gem` to install the development dependencies)

or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
Expand All @@ -50,16 +51,17 @@ ruby -Ilib script.rb
## Getting Started

Please follow the [installation](#installation) procedure and then run the following code:

```ruby
# Load the gem
require 'petstore'

api_instance = Petstore::AnotherFakeApi.new
client = Petstore::Client.new # Client | client model
body = Petstore::Client.new # Client | client model

begin
#To test special tags
result = api_instance.call_123_test_special_tags(client)
result = api_instance.call_123_test_special_tags(body)
p result
rescue Petstore::ApiError => e
puts "Exception when calling AnotherFakeApi->call_123_test_special_tags: #{e}"
Expand All @@ -74,6 +76,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*Petstore::AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
*Petstore::FakeApi* | [**create_xml_item**](docs/FakeApi.md#create_xml_item) | **POST** /fake/create_xml_item | creates an XmlItem
*Petstore::FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
*Petstore::FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
*Petstore::FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
Expand Down Expand Up @@ -112,19 +115,27 @@ Class | Method | HTTP request | Description

## Documentation for Models

- [Petstore::AdditionalPropertiesAnyType](docs/AdditionalPropertiesAnyType.md)
- [Petstore::AdditionalPropertiesArray](docs/AdditionalPropertiesArray.md)
- [Petstore::AdditionalPropertiesBoolean](docs/AdditionalPropertiesBoolean.md)
- [Petstore::AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [Petstore::AdditionalPropertiesInteger](docs/AdditionalPropertiesInteger.md)
- [Petstore::AdditionalPropertiesNumber](docs/AdditionalPropertiesNumber.md)
- [Petstore::AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
- [Petstore::AdditionalPropertiesString](docs/AdditionalPropertiesString.md)
- [Petstore::Animal](docs/Animal.md)
- [Petstore::AnimalFarm](docs/AnimalFarm.md)
- [Petstore::ApiResponse](docs/ApiResponse.md)
- [Petstore::ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [Petstore::ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [Petstore::ArrayTest](docs/ArrayTest.md)
- [Petstore::Capitalization](docs/Capitalization.md)
- [Petstore::Cat](docs/Cat.md)
- [Petstore::CatAllOf](docs/CatAllOf.md)
- [Petstore::Category](docs/Category.md)
- [Petstore::ClassModel](docs/ClassModel.md)
- [Petstore::Client](docs/Client.md)
- [Petstore::Dog](docs/Dog.md)
- [Petstore::DogAllOf](docs/DogAllOf.md)
- [Petstore::EnumArrays](docs/EnumArrays.md)
- [Petstore::EnumClass](docs/EnumClass.md)
- [Petstore::EnumTest](docs/EnumTest.md)
Expand All @@ -145,22 +156,26 @@ Class | Method | HTTP request | Description
- [Petstore::Pet](docs/Pet.md)
- [Petstore::ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [Petstore::SpecialModelName](docs/SpecialModelName.md)
- [Petstore::StringBooleanMap](docs/StringBooleanMap.md)
- [Petstore::Tag](docs/Tag.md)
- [Petstore::TypeHolderDefault](docs/TypeHolderDefault.md)
- [Petstore::TypeHolderExample](docs/TypeHolderExample.md)
- [Petstore::User](docs/User.md)
- [Petstore::XmlItem](docs/XmlItem.md)


## Documentation for Authorization


### api_key


- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header

### api_key_query


- **Type**: API key
- **API key parameter name**: api_key_query
- **Location**: URL query string
Expand All @@ -171,6 +186,7 @@ Class | Method | HTTP request | Description

### petstore_auth


- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Petstore::AdditionalPropertiesAnyType

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | | [optional]

## Code Sample

```ruby
require 'Petstore'

instance = Petstore::AdditionalPropertiesAnyType.new(name: null)
```


Loading