From 970c0c951f1ffbdb325622e1e439e82c1156b355 Mon Sep 17 00:00:00 2001 From: barcigabri <33417277+barcigabri@users.noreply.github.com> Date: Thu, 1 Jan 2026 01:42:01 +0000 Subject: [PATCH] chore: updating templates for ruby sdk --- .../openapi-generator/ruby/Gemfile.mustache | 2 +- .../openapi-generator/ruby/README.mustache | 54 +++++++++---- .../ruby/base_object.mustache | 75 ------------------- templates/openapi-generator/ruby/gem.mustache | 14 +--- .../openapi-generator/ruby/gemspec.mustache | 6 +- .../ruby/partial_model_generic_doc.mustache | 21 +++++- 6 files changed, 67 insertions(+), 105 deletions(-) diff --git a/templates/openapi-generator/ruby/Gemfile.mustache b/templates/openapi-generator/ruby/Gemfile.mustache index 8e2dcca8..c2e3127c 100644 --- a/templates/openapi-generator/ruby/Gemfile.mustache +++ b/templates/openapi-generator/ruby/Gemfile.mustache @@ -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 diff --git a/templates/openapi-generator/ruby/README.mustache b/templates/openapi-generator/ruby/README.mustache index 6aa9c035..5f589346 100644 --- a/templates/openapi-generator/ruby/README.mustache +++ b/templates/openapi-generator/ruby/README.mustache @@ -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}} @@ -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 @@ -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 @@ -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}} @@ -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}} diff --git a/templates/openapi-generator/ruby/base_object.mustache b/templates/openapi-generator/ruby/base_object.mustache index 6d914e10..d752c497 100644 --- a/templates/openapi-generator/ruby/base_object.mustache +++ b/templates/openapi-generator/ruby/base_object.mustache @@ -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<(?.+)>\z/ - inner_type = Regexp.last_match[:inner_type] - value.map { |v| _deserialize(inner_type, v) } - when /\AHash<(?.+?), (?.+)>\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 @@ -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 diff --git a/templates/openapi-generator/ruby/gem.mustache b/templates/openapi-generator/ruby/gem.mustache index 9536e5d8..a1fa2463 100644 --- a/templates/openapi-generator/ruby/gem.mustache +++ b/templates/openapi-generator/ruby/gem.mustache @@ -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' @@ -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. diff --git a/templates/openapi-generator/ruby/gemspec.mustache b/templates/openapi-generator/ruby/gemspec.mustache index 6f48bc9d..6cc0cff0 100644 --- a/templates/openapi-generator/ruby/gemspec.mustache +++ b/templates/openapi-generator/ruby/gemspec.mustache @@ -2,6 +2,7 @@ =begin {{> api_info}} + =end $:.push File.expand_path("../lib", __FILE__) @@ -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' diff --git a/templates/openapi-generator/ruby/partial_model_generic_doc.mustache b/templates/openapi-generator/ruby/partial_model_generic_doc.mustache index 9d90960c..95bdb710 100644 --- a/templates/openapi-generator/ruby/partial_model_generic_doc.mustache +++ b/templates/openapi-generator/ruby/partial_model_generic_doc.mustache @@ -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}} \ No newline at end of file +{{/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}} +```