Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/openapi-generator/ruby/Gemfile.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ gemspec
group :development, :test do
gem 'rake', '~> 13.0.1'
gem 'pry-byebug'
gem 'rubocop', '~> 1.12.0'
gem 'rubocop', '~> 0.66.0'
end
54 changes: 41 additions & 13 deletions templates/openapi-generator/ruby/README.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# FattureInCloud Ruby SDK

[![Ruby Gems](https://img.shields.io/gem/v/fattureincloud_ruby_sdk?color=g)](https://rubygems.org/gems/fattureincloud_ruby_sdk) ![unit tests](https://github.com/fattureincloud/fattureincloud-ruby-sdk/actions/workflows/validate.yaml/badge.svg)
# {{gemName}}

{{moduleName}} - the Ruby gem for the {{appName}}

Expand All @@ -15,21 +13,48 @@ This SDK is automatically generated by the [OpenAPI Generator](https://openapi-g
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Generator version: {{generatorVersion}}
- Build package: {{generatorClass}}


{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Installation

### RubyGems
### Build a gem

To build the Ruby code into a gem:

```shell
gem build {{{gemName}}}.gemspec
```

Then either install the gem locally:

```shell
gem install ./{{{gemName}}}-{{{gemVersion}}}.gem
```

(for development, run `gem install --dev ./{{{gemName}}}-{{{gemVersion}}}.gem` to install the development dependencies)

or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).

Finally add this to the Gemfile:

gem '{{{gemName}}}', '~> {{{gemVersion}}}'

### Install from Git

If the Ruby gem is hosted at a git repository: https://{{gitHost}}/{{gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile:

gem '{{{gemName}}}', :git => 'https://{{gitHost}}/{{gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git'

### Include the Ruby code directly

To install the gem via [RubyGems](https://rubygems.org/), run the following command:
Include the Ruby code directly using `-I` as follows:

```sh
$ gem install fattureincloud_ruby_sdk
```shell
ruby -Ilib script.rb
```

## Getting Started
Expand All @@ -50,9 +75,9 @@ require '{{{gemName}}}'
# Configure a proc to get access tokens in lieu of the static access_token configuration
config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' } {{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
config.api_key['{{{name}}}'] = 'YOUR API KEY'
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# config.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
config.access_token = 'YOUR ACCESS TOKEN'
# Configure a proc to get access tokens in lieu of the static access_token configuration
Expand All @@ -61,6 +86,10 @@ require '{{{gemName}}}'
# Configure faraday connection
config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
{{/isFaraday}}
{{#isHttpx}}
# Configure httpx session
config.configure_session { |session| 'YOUR CONNECTION CONFIG PROC' }
{{/isHttpx}}
{{/authMethods}}end
{{/hasAuthMethods}}

Expand Down Expand Up @@ -127,8 +156,7 @@ Class | Method | HTTP request | Description
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}}
- **{{{scope}}}**: {{{description}}}
{{#scopes}} - {{scope}}: {{description}}
{{/scopes}}
{{/isOAuth}}

Expand Down
75 changes: 0 additions & 75 deletions templates/openapi-generator/ruby/base_object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,6 @@
new(transformed_hash)
end

# Deserializes the data based on type
# @param string type Data type
# @param string value Value to be deserialized
# @return [Object] Deserialized data
def self._deserialize(type, value)
case type.to_sym
when :Time
Time.parse(value)
when :Date
Date.parse(value)
when :String
value.to_s
when :Integer
value.to_i
when :Float
value.to_f
when :Boolean
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
true
else
false
end
when :Object
# generic object (usually a Hash), return directly
value
when /\AArray<(?<inner_type>.+)>\z/
inner_type = Regexp.last_match[:inner_type]
value.map { |v| _deserialize(inner_type, v) }
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
k_type = Regexp.last_match[:k_type]
v_type = Regexp.last_match[:v_type]
{}.tap do |hash|
value.each do |k, v|
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
end
end
when :Hash
value
else # model
# models (e.g. Pet) or oneOf
klass = {{moduleName}}.const_get(type)
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
end
end

# Returns the string representation of the object
# @return [String] String presentation of the object
def to_s
to_hash.to_s
end

# to_body is an alias to to_hash (backward compatibility)
# @return [Hash] Returns the object in the form of hash
def to_body
to_hash
end

# Returns the object in the form of hash
# @return [Hash] Returns the object in the form of hash
def to_hash
Expand All @@ -96,21 +39,3 @@
end
hash
end

# Outputs non-array value in the form of hash
# For object, use to_hash. Otherwise, just return the value
# @param [Object] value Any valid value
# @return [Hash] Returns the value in the form of hash
def _to_hash(value)
if value.is_a?(Array)
value.compact.map { |v| _to_hash(v) }
elsif value.is_a?(Hash)
{}.tap do |hash|
value.each { |k, v| hash[k] = _to_hash(v) }
end
elsif value.respond_to? :to_hash
value.to_hash
else
value
end
end
14 changes: 2 additions & 12 deletions templates/openapi-generator/ruby/gem.mustache
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
=begin
{{> api_info}}

=end

# Common files
require '{{gemName}}/api_client'
require '{{gemName}}/api_error'
require '{{gemName}}/api_model_base'
require '{{gemName}}/version'
require '{{gemName}}/configuration'

Expand Down Expand Up @@ -45,18 +47,6 @@ require '{{importPath}}'
{{/apis}}
{{/apiInfo}}

# Filter
require 'fattureincloud_ruby_sdk/filter/operator'
require 'fattureincloud_ruby_sdk/filter/condition'
require 'fattureincloud_ruby_sdk/filter/conjunction'
require 'fattureincloud_ruby_sdk/filter/disjunction'
require 'fattureincloud_ruby_sdk/filter/filter'
require 'fattureincloud_ruby_sdk/filter/expression'

# OAuth
require 'fattureincloud_ruby_sdk/oauth2/oauth2'
require 'fattureincloud_ruby_sdk/oauth2/scope'

module {{moduleName}}
class << self
# Customize default settings for the SDK using block.
Expand Down
6 changes: 3 additions & 3 deletions templates/openapi-generator/ruby/gemspec.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

=begin
{{> api_info}}

=end

$:.push File.expand_path("../lib", __FILE__)
Expand All @@ -17,14 +18,13 @@ 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}}Unlicense{{/gemLicense}}"
s.required_ruby_version = ">= {{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}2.7{{/gemRequiredRubyVersion}}"
s.metadata = {{{gemMetadata}}}{{^gemMetadata}}{}{{/gemMetadata}}
s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 2.7{{/gemRequiredRubyVersion}}"
s.metadata = {{{gemMetadata}}}{{^gemMetadata}}{}{{/gemMetadata}}

{{#isFaraday}}
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
s.add_runtime_dependency 'faraday-multipart'
s.add_runtime_dependency 'marcel'

{{/isFaraday}}
{{#isTyphoeus}}
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@
| ---- | ---- | ----------- | ----- |
{{#vars}}
| **{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#isReadOnly}}[readonly]{{/isReadOnly}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}} |
{{/vars}}
{{/vars}}

## Example

```ruby
require '{{{gemName}}}'

{{^vars}}
instance = {{moduleName}}::{{classname}}.new()
{{/vars}}
{{#vars}}
{{#-first}}
instance = {{moduleName}}::{{classname}}.new(
{{/-first}}
{{name}}: {{example}}{{^-last}},{{/-last}}
{{#-last}}
)
{{/-last}}
{{/vars}}
```