From f31a47661b049e9f589ee2951efc099fabce26dc Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Fri, 13 Jul 2018 23:28:17 +0900 Subject: [PATCH 01/86] [Ruby] Rename files/folders (#534) * Rename templateDir: rails5 -> ruby-on-rails-server * Rename script: rails5-petstore-server.sh -> ruby-on-rails-server-petstore.sh * Rename sample folder: rails5 -> ruby-on-rails * Rename script(openapi3): rails5-petstore-server.sh -> ruby-on-rails-server-petstore.sh * Update ruby-on-rails-server-petstore.sh * Rename templateDir: sinatra -> ruby-sinatra-server * Rename script: sinatra-petstore-server.sh -> ruby-sinatra-server-petstore.sh * Rename sample folder: sinatra -> ruby-sinatra * Update script * Rename templateDir: ruby -> ruby-client * Rename script: ruby-petstore.sh -> ruby-client-petstore.sh * Update scripts * Update samples - bin/ruby-sinatra-server-petstore.sh - bin/ruby-on-rails-server-petstore.sh - bin/ruby-client-petstore.sh - bin/security/ruby-client-petstore.sh --- Gemfile.mustache | 7 + README.mustache | 137 +++++++++++ Rakefile.mustache | 10 + api.mustache | 192 +++++++++++++++ api_client.mustache | 383 ++++++++++++++++++++++++++++++ api_client_spec.mustache | 218 +++++++++++++++++ api_doc.mustache | 85 +++++++ api_error.mustache | 30 +++ api_info.mustache | 12 + api_test.mustache | 47 ++++ base_object.mustache | 103 ++++++++ base_object_spec.mustache | 109 +++++++++ configuration.mustache | 223 +++++++++++++++++ configuration_spec.mustache | 34 +++ gem.mustache | 40 ++++ gemspec.mustache | 42 ++++ git_push.sh.mustache | 55 +++++ gitignore.mustache | 39 +++ model.mustache | 18 ++ model_doc.mustache | 9 + model_test.mustache | 48 ++++ partial_model_enum_class.mustache | 13 + partial_model_generic.mustache | 279 ++++++++++++++++++++++ rspec.mustache | 2 + rubocop.mustache | 154 ++++++++++++ spec_helper.mustache | 103 ++++++++ version.mustache | 7 + 27 files changed, 2399 insertions(+) create mode 100644 Gemfile.mustache create mode 100644 README.mustache create mode 100644 Rakefile.mustache create mode 100644 api.mustache create mode 100644 api_client.mustache create mode 100644 api_client_spec.mustache create mode 100644 api_doc.mustache create mode 100644 api_error.mustache create mode 100644 api_info.mustache create mode 100644 api_test.mustache create mode 100644 base_object.mustache create mode 100644 base_object_spec.mustache create mode 100644 configuration.mustache create mode 100644 configuration_spec.mustache create mode 100644 gem.mustache create mode 100644 gemspec.mustache create mode 100755 git_push.sh.mustache create mode 100644 gitignore.mustache create mode 100644 model.mustache create mode 100644 model_doc.mustache create mode 100644 model_test.mustache create mode 100644 partial_model_enum_class.mustache create mode 100644 partial_model_generic.mustache create mode 100644 rspec.mustache create mode 100644 rubocop.mustache create mode 100644 spec_helper.mustache create mode 100644 version.mustache diff --git a/Gemfile.mustache b/Gemfile.mustache new file mode 100644 index 000000000000..d255a3ab238d --- /dev/null +++ b/Gemfile.mustache @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gemspec + +group :development, :test do + gem 'rake', '~> 12.0.0' +end diff --git a/README.mustache b/README.mustache new file mode 100644 index 000000000000..8703af147ad7 --- /dev/null +++ b/README.mustache @@ -0,0 +1,137 @@ +# {{gemName}} + +{{moduleName}} - the Ruby gem for the {{appName}} + +{{#appDescriptionWithNewLines}} +{{{appDescriptionWithNewLines}}} +{{/appDescriptionWithNewLines}} + +This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: {{appVersion}} +- Package version: {{gemVersion}} +{{^hideGenerationTimestamp}} +- Build date: {{generatedDate}} +{{/hideGenerationTimestamp}} +- Build package: {{generatorClass}} +{{#infoUrl}} +For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) +{{/infoUrl}} + +## Installation + +### 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://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile: + + gem '{{{gemName}}}', :git => 'https://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git' + +### Include the Ruby code directly + +Include the Ruby code directly using `-I` as follows: + +```shell +ruby -Ilib script.rb +``` + +## Getting Started + +Please follow the [installation](#installation) procedure and then run the following code: +```ruby +# Load the gem +require '{{{gemName}}}' +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}} +# Setup authorization +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} + # Configure HTTP basic authorization: {{{name}}} + config.username = 'YOUR USERNAME' + config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}} + # Configure API key authorization: {{{name}}} + 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['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} + # Configure OAuth2 access token for authorization: {{{name}}} + config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} +{{/authMethods}}end +{{/hasAuthMethods}} + +api_instance = {{{moduleName}}}::{{{classname}}}.new +{{#requiredParams}} +{{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}} +{{/requiredParams}} +{{#optionalParams}} +{{#-first}} +opts = { +{{/-first}} + {{{paramName}}}: {{{example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} +{{#-last}} +} +{{/-last}} +{{/optionalParams}} + +begin +{{#summary}} #{{{.}}} +{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}{{#returnType}} + p result{{/returnType}} +rescue {{{moduleName}}}::ApiError => e + puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}" +end +{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} +``` + +## Documentation for API Endpoints + +All URIs are relative to *{{basePath}}* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}::{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} + +## Documentation for Models + +{{#models}}{{#model}} - [{{moduleName}}::{{classname}}]({{modelDocPath}}{{classname}}.md) +{{/model}}{{/models}} + +## Documentation for Authorization + +{{^authMethods}} All endpoints do not require authorization. +{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} +{{#authMethods}}### {{name}} + +{{#isApiKey}}- **Type**: API key +- **API key parameter name**: {{keyParamName}} +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} +{{/isApiKey}} +{{#isBasic}}- **Type**: HTTP basic authentication +{{/isBasic}} +{{#isOAuth}}- **Type**: OAuth +- **Flow**: {{flow}} +- **Authorization URL**: {{authorizationUrl}} +- **Scopes**: {{^scopes}}N/A{{/scopes}} +{{#scopes}} - {{scope}}: {{description}} +{{/scopes}} +{{/isOAuth}} + +{{/authMethods}} diff --git a/Rakefile.mustache b/Rakefile.mustache new file mode 100644 index 000000000000..c72ca30d454e --- /dev/null +++ b/Rakefile.mustache @@ -0,0 +1,10 @@ +require "bundler/gem_tasks" + +begin + require 'rspec/core/rake_task' + + RSpec::Core::RakeTask.new(:spec) + task default: :spec +rescue LoadError + # no rspec available +end diff --git a/api.mustache b/api.mustache new file mode 100644 index 000000000000..aef0fbb24c99 --- /dev/null +++ b/api.mustache @@ -0,0 +1,192 @@ +=begin +{{> api_info}} +=end + +require 'uri' + +module {{moduleName}} +{{#operations}} + class {{classname}} + attr_accessor :api_client + + def initialize(api_client = ApiClient.default) + @api_client = api_client + end +{{#operation}} + {{#summary}} + # {{{summary}}} + {{/summary}} + {{#notes}} + # {{{notes}}} + {{/notes}} +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} +{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] + def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) + {{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts) + {{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}} + end + + {{#summary}} + # {{summary}} + {{/summary}} + {{#notes}} + # {{notes}} + {{/notes}} +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} +{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers + def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' + end + {{#allParams}} + {{#required}} + # verify the required parameter '{{paramName}}' is set + if @api_client.config.client_side_validation && {{{paramName}}}.nil? + fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}" + end + {{#isEnum}} + {{^isContainer}} + # verify enum value + if @api_client.config.client_side_validation && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) + fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" + end + {{/isContainer}} + {{/isEnum}} + {{/required}} + {{^required}} + {{#isEnum}} + {{#collectionFormat}} + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(item) } + fail ArgumentError, 'invalid value for "{{{paramName}}}", must include one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + end + {{/collectionFormat}} + {{^collectionFormat}} + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) + fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + end + {{/collectionFormat}} + {{/isEnum}} + {{/required}} + {{#hasValidation}} + {{#maxLength}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.' + end + + {{/maxLength}} + {{#minLength}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.' + end + + {{/minLength}} + {{#maximum}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.' + end + + {{/maximum}} + {{#minimum}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.' + end + + {{/minimum}} + {{#pattern}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}}) + fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}." + end + + {{/pattern}} + {{#maxItems}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length > {{{maxItems}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{{maxItems}}}.' + end + + {{/maxItems}} + {{#minItems}} + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length < {{{minItems}}} + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{{minItems}}}.' + end + + {{/minItems}} + {{/hasValidation}} + {{/allParams}} + # resource path + local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} + + # query parameters + query_params = {} + {{#queryParams}} + {{#required}} + query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} + {{/required}} + {{/queryParams}} + {{#queryParams}} + {{^required}} + query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? + {{/required}} + {{/queryParams}} + + # header parameters + header_params = {} + {{#hasProduces}} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) + {{/hasProduces}} + {{#hasConsumes}} + # HTTP header 'Content-Type' + header_params['Content-Type'] = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]) + {{/hasConsumes}} + {{#headerParams}} + {{#required}} + header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} + {{/required}} + {{/headerParams}} + {{#headerParams}} + {{^required}} + header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? + {{/required}} + {{/headerParams}} + + # form parameters + form_params = {} + {{#formParams}} + {{#required}} + form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} + {{/required}} + {{/formParams}} + {{#formParams}} + {{^required}} + form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{paramName}}'].nil? + {{/required}} + {{/formParams}} + + # http body (model) + {{^bodyParam}} + post_body = nil + {{/bodyParam}} + {{#bodyParam}} + post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) + {{/bodyParam}} + auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] + data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names{{#returnType}}, + :return_type => '{{{returnType}}}'{{/returnType}}) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end +{{/operation}} + end +{{/operations}} +end diff --git a/api_client.mustache b/api_client.mustache new file mode 100644 index 000000000000..33feac7acdf0 --- /dev/null +++ b/api_client.mustache @@ -0,0 +1,383 @@ +=begin +{{> api_info}} +=end + +require 'date' +require 'json' +require 'logger' +require 'tempfile' +require 'typhoeus' +require 'uri' + +module {{moduleName}} + class ApiClient + # The Configuration object holding settings to be used in the API client. + attr_accessor :config + + # Defines the headers to be used in HTTP requests of all API calls by default. + # + # @return [Hash] + attr_accessor :default_headers + + # Initializes the ApiClient + # @option config [Configuration] Configuration for initializing the object, default to Configuration.default + def initialize(config = Configuration.default) + @config = config + @user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/#{VERSION}/ruby{{/httpUserAgent}}" + @default_headers = { + 'Content-Type' => 'application/json', + 'User-Agent' => @user_agent + } + end + + def self.default + @@default ||= ApiClient.new + end + + # Call an API with given options. + # + # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. + def call_api(http_method, path, opts = {}) + request = build_request(http_method, path, opts) + response = request.run + + if @config.debugging + @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" + end + + unless response.success? + if response.timed_out? + fail ApiError.new('Connection timed out') + elsif response.code == 0 + # Errors from libcurl will be made visible here + fail ApiError.new(:code => 0, + :message => response.return_message) + else + fail ApiError.new(:code => response.code, + :response_headers => response.headers, + :response_body => response.body), + response.status_message + end + end + + if opts[:return_type] + data = deserialize(response, opts[:return_type]) + else + data = nil + end + return data, response.code, response.headers + end + + # Builds the HTTP request + # + # @param [String] http_method HTTP method/verb (e.g. POST) + # @param [String] path URL path (e.g. /account/new) + # @option opts [Hash] :header_params Header parameters + # @option opts [Hash] :query_params Query parameters + # @option opts [Hash] :form_params Query parameters + # @option opts [Object] :body HTTP body (JSON/XML) + # @return [Typhoeus::Request] A Typhoeus Request + def build_request(http_method, path, opts = {}) + url = build_request_url(path) + http_method = http_method.to_sym.downcase + + header_params = @default_headers.merge(opts[:header_params] || {}) + query_params = opts[:query_params] || {} + form_params = opts[:form_params] || {} + + {{#hasAuthMethods}} + update_params_for_auth! header_params, query_params, opts[:auth_names] + {{/hasAuthMethods}} + + # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) + _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 + + req_opts = { + :method => http_method, + :headers => header_params, + :params => query_params, + :params_encoding => @config.params_encoding, + :timeout => @config.timeout, + :ssl_verifypeer => @config.verify_ssl, + :ssl_verifyhost => _verify_ssl_host, + :sslcert => @config.cert_file, + :sslkey => @config.key_file, + :verbose => @config.debugging + } + + # set custom cert, if provided + req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert + + if [:post, :patch, :put, :delete].include?(http_method) + req_body = build_request_body(header_params, form_params, opts[:body]) + req_opts.update :body => req_body + if @config.debugging + @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" + end + end + + request = Typhoeus::Request.new(url, req_opts) + download_file(request) if opts[:return_type] == 'File' + request + end + + # Check if the given MIME is a JSON MIME. + # JSON MIME examples: + # application/json + # application/json; charset=UTF8 + # APPLICATION/JSON + # */* + # @param [String] mime MIME + # @return [Boolean] True if the MIME is application/json + def json_mime?(mime) + (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil? + end + + # Deserialize the response to the given return type. + # + # @param [Response] response HTTP response + # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]" + def deserialize(response, return_type) + body = response.body + + # handle file downloading - return the File instance processed in request callbacks + # note that response body is empty when the file is written in chunks in request on_body callback + return @tempfile if return_type == 'File' + + return nil if body.nil? || body.empty? + + # return response body directly for String return type + return body if return_type == 'String' + + # ensuring a default content type + content_type = response.headers['Content-Type'] || 'application/json' + + fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) + + begin + data = JSON.parse("[#{body}]", :symbolize_names => true)[0] + rescue JSON::ParserError => e + if %w(String Date DateTime).include?(return_type) + data = body + else + raise e + end + end + + convert_to_type data, return_type + end + + # Convert data to the given return type. + # @param [Object] data Data to be converted + # @param [String] return_type Return type + # @return [Mixed] Data in a particular type + def convert_to_type(data, return_type) + return nil if data.nil? + case return_type + when 'String' + data.to_s + when 'Integer' + data.to_i + when 'Float' + data.to_f + when 'BOOLEAN' + data == true + when 'DateTime' + # parse date time (expecting ISO 8601 format) + DateTime.parse data + when 'Date' + # parse date time (expecting ISO 8601 format) + Date.parse data + when 'Object' + # generic object (usually a Hash), return directly + data + when /\AArray<(.+)>\z/ + # e.g. Array + sub_type = $1 + data.map { |item| convert_to_type(item, sub_type) } + when /\AHash\\z/ + # e.g. Hash + sub_type = $1 + {}.tap do |hash| + data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } + end + else + # models, e.g. Pet + {{moduleName}}.const_get(return_type).new.tap do |model| + model.build_from_hash data + end + end + end + + # Save response body into a file in (the defined) temporary folder, using the filename + # from the "Content-Disposition" header if provided, otherwise a random filename. + # The response body is written to the file in chunks in order to handle files which + # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby + # process can use. + # + # @see Configuration#temp_folder_path + def download_file(request) + tempfile = nil + encoding = nil + request.on_headers do |response| + content_disposition = response.headers['Content-Disposition'] + if content_disposition && content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = response.body.encoding + tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile = tempfile + end + request.on_body do |chunk| + chunk.force_encoding(encoding) + tempfile.write(chunk) + end + request.on_complete do |response| + tempfile.close + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + end + end + + # Sanitize filename by removing path. + # e.g. ../../sun.gif becomes sun.gif + # + # @param [String] filename the filename to be sanitized + # @return [String] the sanitized filename + def sanitize_filename(filename) + filename.gsub(/.*[\/\\]/, '') + end + + def build_request_url(path) + # Add leading and trailing slashes to path + path = "/#{path}".gsub(/\/+/, '/') + URI.encode(@config.base_url + path) + end + + # Builds the HTTP request body + # + # @param [Hash] header_params Header parameters + # @param [Hash] form_params Query parameters + # @param [Object] body HTTP body (JSON/XML) + # @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' + data = {} + form_params.each do |key, value| + case value + when ::File, ::Array, nil + # let typhoeus handle File, Array and nil parameters + data[key] = value + else + data[key] = value.to_s + end + end + elsif body + data = body.is_a?(String) ? body : body.to_json + else + data = nil + end + data + end + + # Update hearder and query params based on authentication settings. + # + # @param [Hash] header_params Header parameters + # @param [Hash] query_params Query parameters + # @param [String] auth_names Authentication scheme name + def update_params_for_auth!(header_params, query_params, auth_names) + Array(auth_names).each do |auth_name| + auth_setting = @config.auth_settings[auth_name] + next unless auth_setting + case auth_setting[:in] + when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] + when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] + else fail ArgumentError, 'Authentication token must be in `query` of `header`' + end + end + end + + # Sets user agent in HTTP header + # + # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) + def user_agent=(user_agent) + @user_agent = user_agent + @default_headers['User-Agent'] = @user_agent + end + + # Return Accept header based on an array of accepts provided. + # @param [Array] accepts array for Accept + # @return [String] the Accept header (e.g. application/json) + def select_header_accept(accepts) + return nil if accepts.nil? || accepts.empty? + # use JSON when present, otherwise use all of the provided + json_accept = accepts.find { |s| json_mime?(s) } + json_accept || accepts.join(',') + end + + # Return Content-Type header based on an array of content types provided. + # @param [Array] content_types array for Content-Type + # @return [String] the Content-Type header (e.g. application/json) + def select_header_content_type(content_types) + # use application/json by default + return 'application/json' if content_types.nil? || content_types.empty? + # use JSON when present, otherwise use the first one + json_content_type = content_types.find { |s| json_mime?(s) } + json_content_type || content_types.first + end + + # Convert object (array, hash, object, etc) to JSON string. + # @param [Object] model object to be converted into JSON string + # @return [String] JSON string representation of the object + def object_to_http_body(model) + return model if model.nil? || model.is_a?(String) + local_body = nil + if model.is_a?(Array) + local_body = model.map { |m| object_to_hash(m) } + else + local_body = object_to_hash(model) + end + local_body.to_json + end + + # Convert object(non-array) to hash. + # @param [Object] obj object to be converted into JSON string + # @return [String] JSON string representation of the object + def object_to_hash(obj) + if obj.respond_to?(:to_hash) + obj.to_hash + else + obj + end + end + + # Build parameter value according to the given collection format. + # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi + def build_collection_param(param, collection_format) + case collection_format + when :csv + param.join(',') + when :ssv + param.join(' ') + when :tsv + param.join("\t") + when :pipes + param.join('|') + when :multi + # return the array directly as typhoeus will handle it as expected + param + else + fail "unknown collection format: #{collection_format.inspect}" + end + end + end +end diff --git a/api_client_spec.mustache b/api_client_spec.mustache new file mode 100644 index 000000000000..b887b92f31a3 --- /dev/null +++ b/api_client_spec.mustache @@ -0,0 +1,218 @@ +=begin +{{> api_info}} +=end + +require 'spec_helper' + +describe {{moduleName}}::ApiClient do + context 'initialization' do + context 'URL stuff' do + context 'host' do + it 'removes http from host' do + {{moduleName}}.configure { |c| c.host = 'http://example.com' } + expect({{moduleName}}::Configuration.default.host).to eq('example.com') + end + + it 'removes https from host' do + {{moduleName}}.configure { |c| c.host = 'https://wookiee.com' } + expect({{moduleName}}::ApiClient.default.config.host).to eq('wookiee.com') + end + + it 'removes trailing path from host' do + {{moduleName}}.configure { |c| c.host = 'hobo.com/v4' } + expect({{moduleName}}::Configuration.default.host).to eq('hobo.com') + end + end + + context 'base_path' do + it "prepends a slash to base_path" do + {{moduleName}}.configure { |c| c.base_path = 'v4/dog' } + expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog') + end + + it "doesn't prepend a slash if one is already there" do + {{moduleName}}.configure { |c| c.base_path = '/v4/dog' } + expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog') + end + + it "ends up as a blank string if nil" do + {{moduleName}}.configure { |c| c.base_path = nil } + expect({{moduleName}}::Configuration.default.base_path).to eq('') + end + end + end + end + + describe 'params_encoding in #build_request' do + let(:config) { {{moduleName}}::Configuration.new } + let(:api_client) { {{moduleName}}::ApiClient.new(config) } + + it 'defaults to nil' do + expect({{moduleName}}::Configuration.default.params_encoding).to eq(nil) + expect(config.params_encoding).to eq(nil) + + request = api_client.build_request(:get, '/test') + expect(request.options[:params_encoding]).to eq(nil) + end + + it 'can be customized' do + config.params_encoding = :multi + request = api_client.build_request(:get, '/test') + expect(request.options[:params_encoding]).to eq(:multi) + end + end + + describe 'timeout in #build_request' do + let(:config) { {{moduleName}}::Configuration.new } + let(:api_client) { {{moduleName}}::ApiClient.new(config) } + + it 'defaults to 0' do + expect({{moduleName}}::Configuration.default.timeout).to eq(0) + expect(config.timeout).to eq(0) + + request = api_client.build_request(:get, '/test') + expect(request.options[:timeout]).to eq(0) + end + + it 'can be customized' do + config.timeout = 100 + request = api_client.build_request(:get, '/test') + expect(request.options[:timeout]).to eq(100) + end + end + + describe '#deserialize' do + it "handles Array" do + api_client = {{moduleName}}::ApiClient.new + headers = { 'Content-Type' => 'application/json' } + response = double('response', headers: headers, body: '[12, 34]') + data = api_client.deserialize(response, 'Array') + expect(data).to be_instance_of(Array) + expect(data).to eq([12, 34]) + end + + it 'handles Array>' do + api_client = {{moduleName}}::ApiClient.new + headers = { 'Content-Type' => 'application/json' } + response = double('response', headers: headers, body: '[[12, 34], [56]]') + data = api_client.deserialize(response, 'Array>') + expect(data).to be_instance_of(Array) + expect(data).to eq([[12, 34], [56]]) + end + + it 'handles Hash' do + api_client = {{moduleName}}::ApiClient.new + headers = { 'Content-Type' => 'application/json' } + response = double('response', headers: headers, body: '{"message": "Hello"}') + data = api_client.deserialize(response, 'Hash') + expect(data).to be_instance_of(Hash) + expect(data).to eq(:message => 'Hello') + end + end + + describe "#object_to_hash" do + it 'ignores nils and includes empty arrays' do + # uncomment below to test object_to_hash for model + # api_client = {{moduleName}}::ApiClient.new + # _model = {{moduleName}}::ModelName.new + # update the model attribute below + # _model.id = 1 + # update the expected value (hash) below + # expected = {id: 1, name: '', tags: []} + # expect(api_client.object_to_hash(_model)).to eq(expected) + end + end + + describe '#build_collection_param' do + let(:param) { ['aa', 'bb', 'cc'] } + let(:api_client) { {{moduleName}}::ApiClient.new } + + it 'works for csv' do + expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc') + end + + it 'works for ssv' do + expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc') + end + + it 'works for tsv' do + expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc") + end + + it 'works for pipes' do + expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc') + end + + it 'works for multi' do + expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc']) + end + + it 'fails for invalid collection format' do + expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID') + end + end + + describe '#json_mime?' do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it 'works' do + expect(api_client.json_mime?(nil)).to eq false + expect(api_client.json_mime?('')).to eq false + + expect(api_client.json_mime?('application/json')).to eq true + expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true + expect(api_client.json_mime?('APPLICATION/JSON')).to eq true + + expect(api_client.json_mime?('application/xml')).to eq false + expect(api_client.json_mime?('text/plain')).to eq false + expect(api_client.json_mime?('application/jsonp')).to eq false + end + end + + describe '#select_header_accept' do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it 'works' do + expect(api_client.select_header_accept(nil)).to be_nil + expect(api_client.select_header_accept([])).to be_nil + + expect(api_client.select_header_accept(['application/json'])).to eq('application/json') + expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') + expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') + + expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml') + expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml') + end + end + + describe '#select_header_content_type' do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it 'works' do + expect(api_client.select_header_content_type(nil)).to eq('application/json') + expect(api_client.select_header_content_type([])).to eq('application/json') + + expect(api_client.select_header_content_type(['application/json'])).to eq('application/json') + expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') + expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') + expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml') + expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain') + end + end + + describe '#sanitize_filename' do + let(:api_client) { {{moduleName}}::ApiClient.new } + + it 'works' do + expect(api_client.sanitize_filename('sun')).to eq('sun') + expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif') + expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif') + end + end +end diff --git a/api_doc.mustache b/api_doc.mustache new file mode 100644 index 000000000000..5f6f5bb5a5a9 --- /dev/null +++ b/api_doc.mustache @@ -0,0 +1,85 @@ +# {{moduleName}}::{{classname}}{{#description}} +{{description}}{{/description}} + +All URIs are relative to *{{basePath}}* + +Method | HTTP request | Description +------------- | ------------- | ------------- +{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} +{{/operation}}{{/operations}} + +{{#operations}} +{{#operation}} +# **{{operationId}}** +> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} + +{{{summary}}}{{#notes}} + +{{{notes}}}{{/notes}} + +### Example +```ruby +# load the gem +require '{{{gemName}}}' +{{#hasAuthMethods}} +# setup authorization +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} + # Configure HTTP basic authorization: {{{name}}} + config.username = 'YOUR USERNAME' + config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}} + # Configure API key authorization: {{{name}}} + 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['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} + # Configure OAuth2 access token for authorization: {{{name}}} + config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} +{{/authMethods}}end +{{/hasAuthMethods}} + +api_instance = {{{moduleName}}}::{{{classname}}}.new +{{#requiredParams}} +{{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}} +{{/requiredParams}} +{{#optionalParams}} +{{#-first}} +opts = { +{{/-first}} + {{{paramName}}}: {{{example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} +{{#-last}} +} +{{/-last}} +{{/optionalParams}} + +begin +{{#summary}} #{{{.}}} +{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}{{#returnType}} + p result{{/returnType}} +rescue {{{moduleName}}}::ApiError => e + puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}" +end +``` + +### Parameters +{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} +Name | Type | Description | Notes +------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} +{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{/allParams}} + +### Return type + +{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil (empty response body){{/returnType}} + +### Authorization + +{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}} + +### HTTP request headers + + - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} + - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} + + + +{{/operation}} +{{/operations}} diff --git a/api_error.mustache b/api_error.mustache new file mode 100644 index 000000000000..b3320779b36e --- /dev/null +++ b/api_error.mustache @@ -0,0 +1,30 @@ +=begin +{{> api_info}} +=end + +module {{moduleName}} + class ApiError < StandardError + attr_reader :code, :response_headers, :response_body + + # Usage examples: + # ApiError.new + # ApiError.new("message") + # ApiError.new(:code => 500, :response_headers => {}, :response_body => "") + # ApiError.new(:code => 404, :message => "Not Found") + def initialize(arg = nil) + if arg.is_a? Hash + if arg.key?(:message) || arg.key?('message') + super(arg[:message] || arg['message']) + else + super arg + end + + arg.each do |k, v| + instance_variable_set "@#{k}", v + end + else + super arg + end + end + end +end diff --git a/api_info.mustache b/api_info.mustache new file mode 100644 index 000000000000..207e8fb31c65 --- /dev/null +++ b/api_info.mustache @@ -0,0 +1,12 @@ +{{#appName}} +#{{{appName}}} + +{{/appName}} +{{#appDescription}} +#{{{appDescription}}} + +{{/appDescription}} +{{#version}}OpenAPI spec version: {{version}}{{/version}} +{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} +Generated by: https://openapi-generator.tech +OpenAPI Generator version: {{{generatorVersion}}} diff --git a/api_test.mustache b/api_test.mustache new file mode 100644 index 000000000000..ee3c6e18b555 --- /dev/null +++ b/api_test.mustache @@ -0,0 +1,47 @@ +=begin +{{> api_info}} +=end + +require 'spec_helper' +require 'json' + +# Unit tests for {{moduleName}}::{{classname}} +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +{{#operations}}describe '{{classname}}' do + before do + # run before each test + @instance = {{moduleName}}::{{classname}}.new + end + + after do + # run after each test + end + + describe 'test an instance of {{classname}}' do + it 'should create an instance of {{classname}}' do + expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) + end + end + +{{#operation}} + # unit tests for {{operationId}} + {{#summary}} + # {{summary}} + {{/summary}} + {{#notes}} + # {{notes}} + {{/notes}} +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} +{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] + describe '{{operationId}} test' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +{{/operation}} +end +{{/operations}} diff --git a/base_object.mustache b/base_object.mustache new file mode 100644 index 000000000000..815f5078fc7e --- /dev/null +++ b/base_object.mustache @@ -0,0 +1,103 @@ + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.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 + else # model + temp_model = {{moduleName}}.const_get(type).new + temp_model.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 + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + hash[param] = _to_hash(value) + 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 \ No newline at end of file diff --git a/base_object_spec.mustache b/base_object_spec.mustache new file mode 100644 index 000000000000..50778a95a298 --- /dev/null +++ b/base_object_spec.mustache @@ -0,0 +1,109 @@ +require 'spec_helper' + +class ArrayMapObject < Petstore::Category + attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map, :boolean_true_arr, :boolean_false_arr + + def self.attribute_map + { + :int_arr => :int_arr, + :pet_arr => :pet_arr, + :int_map => :int_map, + :pet_map => :pet_map, + :int_arr_map => :int_arr_map, + :pet_arr_map => :pet_arr_map, + :boolean_true_arr => :boolean_true_arr, + :boolean_false_arr => :boolean_false_arr, + } + end + + def self.openapi_types + { + :int_arr => :'Array', + :pet_arr => :'Array', + :int_map => :'Hash', + :pet_map => :'Hash', + :int_arr_map => :'Hash>', + :pet_arr_map => :'Hash>', + :boolean_true_arr => :'Array', + :boolean_false_arr => :'Array', + } + end +end + +describe 'BaseObject' do + describe 'boolean values' do + let(:obj) { Petstore::Cat.new({declawed: false}) } + + it 'should have values set' do + expect(obj.declawed).not_to be_nil + expect(obj.declawed).to eq(false) + end + end + + describe 'array and map properties' do + let(:obj) { ArrayMapObject.new } + + let(:data) do + {int_arr: [123, 456], + pet_arr: [{name: 'Kitty'}], + int_map: {'int' => 123}, + pet_map: {'pet' => {name: 'Kitty'}}, + int_arr_map: {'int_arr' => [123, 456]}, + pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]}, + boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"], + boolean_false_arr: [false, "", 0, "0", "f", nil, "null"], + } + end + + it 'works for #build_from_hash' do + obj.build_from_hash(data) + + expect(obj.int_arr).to match_array([123, 456]) + + expect(obj.pet_arr).to be_instance_of(Array) + expect(obj.pet_arr).to be_instance_of(1) + + pet = obj.pet_arr.first + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') + + expect(obj.int_map).to be_instance_of(Hash) + expect(obj.int_map).to eq({'int' => 123}) + + expect(obj.pet_map).to be_instance_of(Hash) + pet = obj.pet_map['pet'] + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') + + expect(obj.int_arr_map).to be_instance_of(Hash) + arr = obj.int_arr_map['int_arr'] + expect(arr).to match_array([123, 456]) + + expect(obj.pet_arr_map).to be_instance_of(Hash) + arr = obj.pet_arr_map['pet_arr'] + expect(arr).to be_instance_of(Array) + expect(arr.size).to eq(1) + pet = arr.first + expect(pet).to be_instance_of(Petstore::Pet) + expect(pet.name).to eq('Kitty') + + expect(obj.boolean_true_arr).to be_instance_of(Array) + obj.boolean_true_arr.each do |b| + expect(b).to eq(true) + end + + expect(obj.boolean_false_arr).to be_instance_of(Array) + obj.boolean_false_arr.each do |b| + expect(b).to eq(false) + end + end + + it 'works for #to_hash' do + obj.build_from_hash(data) + expect_data = data.dup + expect_data[:boolean_true_arr].map! {true} + expect_data[:boolean_false_arr].map! {false} + expect(obj.to_hash).to eq(expect_data) + end + end +end diff --git a/configuration.mustache b/configuration.mustache new file mode 100644 index 000000000000..7c7e1d82dc5a --- /dev/null +++ b/configuration.mustache @@ -0,0 +1,223 @@ +=begin +{{> api_info}} +=end + +require 'uri' + +module {{moduleName}} + class Configuration + # Defines url scheme + attr_accessor :scheme + + # Defines url host + attr_accessor :host + + # Defines url base path + attr_accessor :base_path + + # Defines API keys used with API Key authentications. + # + # @return [Hash] key: parameter name, value: parameter value (API key) + # + # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string) + # config.api_key['api_key'] = 'xxx' + attr_accessor :api_key + + # Defines API key prefixes used with API Key authentications. + # + # @return [Hash] key: parameter name, value: API key prefix + # + # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers) + # config.api_key_prefix['api_key'] = 'Token' + attr_accessor :api_key_prefix + + # Defines the username used with HTTP basic authentication. + # + # @return [String] + attr_accessor :username + + # Defines the password used with HTTP basic authentication. + # + # @return [String] + attr_accessor :password + + # Defines the access token (Bearer) used with OAuth2. + attr_accessor :access_token + + # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response + # details will be logged with `logger.debug` (see the `logger` attribute). + # Default to false. + # + # @return [true, false] + attr_accessor :debugging + + # Defines the logger used for debugging. + # Default to `Rails.logger` (when in Rails) or logging to STDOUT. + # + # @return [#debug] + attr_accessor :logger + + # Defines the temporary folder to store downloaded files + # (for API endpoints that have file response). + # Default to use `Tempfile`. + # + # @return [String] + attr_accessor :temp_folder_path + + # The time limit for HTTP request in seconds. + # Default to 0 (never times out). + attr_accessor :timeout + + # Set this to false to skip client side validation in the operation. + # Default to true. + # @return [true, false] + attr_accessor :client_side_validation + + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl + + ### TLS/SSL setting + # Set this to false to skip verifying SSL host name + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl_host + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + # + # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: + # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 + attr_accessor :ssl_ca_cert + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :cert_file + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :key_file + + # Set this to customize parameters encoding of array parameter with multi collectionFormat. + # Default to nil. + # + # @see The params_encoding option of Ethon. Related source code: + # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 + attr_accessor :params_encoding + + attr_accessor :inject_format + + attr_accessor :force_ending_format + + def initialize + @scheme = '{{scheme}}' + @host = '{{host}}' + @base_path = '{{contextPath}}' + @api_key = {} + @api_key_prefix = {} + @timeout = 0 + @client_side_validation = true + @verify_ssl = true + @verify_ssl_host = true + @params_encoding = nil + @cert_file = nil + @key_file = nil + @debugging = false + @inject_format = false + @force_ending_format = false + @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + + yield(self) if block_given? + end + + # The default Configuration object. + def self.default + @@default ||= Configuration.new + end + + def configure + yield(self) if block_given? + end + + def scheme=(scheme) + # remove :// from scheme + @scheme = scheme.sub(/:\/\//, '') + end + + def host=(host) + # remove http(s):// and anything after a slash + @host = host.sub(/https?:\/\//, '').split('/').first + end + + def base_path=(base_path) + # Add leading and trailing slashes to base_path + @base_path = "/#{base_path}".gsub(/\/+/, '/') + @base_path = '' if @base_path == '/' + end + + def base_url + url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') + URI.encode(url) + end + + # Gets API key (with prefix if set). + # @param [String] param_name the parameter name of API key auth + def api_key_with_prefix(param_name) + if @api_key_prefix[param_name] + "#{@api_key_prefix[param_name]} #{@api_key[param_name]}" + else + @api_key[param_name] + end + end + + # Gets Basic Auth token string + def basic_auth_token + 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") + end + + # Returns Auth Settings hash for api client. + def auth_settings + { +{{#authMethods}} +{{#isApiKey}} + '{{name}}' => + { + type: 'api_key', + in: {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}, + key: '{{keyParamName}}', + value: api_key_with_prefix('{{keyParamName}}') + }, +{{/isApiKey}} +{{#isBasic}} + '{{name}}' => + { + type: 'basic', + in: 'header', + key: 'Authorization', + value: basic_auth_token + }, +{{/isBasic}} +{{#isOAuth}} + '{{name}}' => + { + type: 'oauth2', + in: 'header', + key: 'Authorization', + value: "Bearer #{access_token}" + }, +{{/isOAuth}} +{{/authMethods}} + } + end + end +end diff --git a/configuration_spec.mustache b/configuration_spec.mustache new file mode 100644 index 000000000000..22a113e8e324 --- /dev/null +++ b/configuration_spec.mustache @@ -0,0 +1,34 @@ +=begin +{{> api_info}} +=end + +require 'spec_helper' + +describe {{moduleName}}::Configuration do + let(:config) { {{moduleName}}::Configuration.default } + + before(:each) do + # uncomment below to setup host and base_path + # require 'URI' + # uri = URI.parse("{{{basePath}}}") + # {{moduleName}}.configure do |c| + # c.host = uri.host + # c.base_path = uri.path + # end + end + + describe '#base_url' do + it 'should have the default value' do + # uncomment below to test default value of the base path + # expect(config.base_url).to eq("{{{basePath}}}") + end + + it 'should remove trailing slashes' do + [nil, '', '/', '//'].each do |base_path| + config.base_path = base_path + # uncomment below to test trailing slashes + # expect(config.base_url).to eq("{{{basePath}}}") + end + end + end +end diff --git a/gem.mustache b/gem.mustache new file mode 100644 index 000000000000..c9ae0ebf96ea --- /dev/null +++ b/gem.mustache @@ -0,0 +1,40 @@ +=begin +{{> api_info}} +=end + +# Common files +require '{{gemName}}/api_client' +require '{{gemName}}/api_error' +require '{{gemName}}/version' +require '{{gemName}}/configuration' + +# Models +{{#models}} +{{#model}} +require '{{gemName}}/{{modelPackage}}/{{classFilename}}'{{/model}} +{{/models}} + +# APIs +{{#apiInfo}} +{{#apis}} +require '{{importPath}}' +{{/apis}} +{{/apiInfo}} + +module {{moduleName}} + class << self + # Customize default settings for the SDK using block. + # {{moduleName}}.configure do |config| + # config.username = "xxx" + # config.password = "xxx" + # end + # If no block given, return the default Configuration object. + def configure + if block_given? + yield(Configuration.default) + else + Configuration.default + end + end + end +end diff --git a/gemspec.mustache b/gemspec.mustache new file mode 100644 index 000000000000..b77bbb503673 --- /dev/null +++ b/gemspec.mustache @@ -0,0 +1,42 @@ +# -*- encoding: utf-8 -*- + +=begin +{{> api_info}} +=end + +$:.push File.expand_path("../lib", __FILE__) +require "{{gemName}}/version" + +Gem::Specification.new do |s| + s.name = "{{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}" + s.version = {{moduleName}}::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["{{gemAuthor}}{{^gemAuthor}}OpenAPI-Generator{{/gemAuthor}}"] + s.email = ["{{gemAuthorEmail}}{{^gemAuthorEmail}}{{infoEmail}}{{/gemAuthorEmail}}"] + s.homepage = "{{gemHomepage}}{{^gemHomepage}}https://openapi-generator.tech{{/gemHomepage}}" + s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" + s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" + {{#gemLicense}} + s.license = '{{{gemLicense}}}' + {{/gemLicense}} + {{^gemLicense}} + s.license = "Unlicense" + {{/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', '~> 2.1', '>= 2.1.0' + + s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' + s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' + s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' + s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6' + s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2' + s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16' + s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12' + + s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } + s.test_files = `find spec/*`.split("\n") + s.executables = [] + s.require_paths = ["lib"] +end diff --git a/git_push.sh.mustache b/git_push.sh.mustache new file mode 100755 index 000000000000..5807579d6eff --- /dev/null +++ b/git_push.sh.mustache @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Generated by: https://openapi-generator.tech +# +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="{{{gitUserId}}}" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="{{{gitRepoId}}}" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="{{{releaseNote}}}" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/gitignore.mustache b/gitignore.mustache new file mode 100644 index 000000000000..05a17cb8f0a0 --- /dev/null +++ b/gitignore.mustache @@ -0,0 +1,39 @@ +# Generated by: https://openapi-generator.tech +# + +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +## Specific to RubyMotion: +.dat* +.repl_history +build/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc diff --git a/model.mustache b/model.mustache new file mode 100644 index 000000000000..04eb79cd53e0 --- /dev/null +++ b/model.mustache @@ -0,0 +1,18 @@ +=begin +{{> api_info}} +=end + +require 'date' + +module {{moduleName}} +{{#models}} +{{#model}} +{{#isEnum}} +{{>partial_model_enum_class}} +{{/isEnum}} +{{^isEnum}} +{{>partial_model_generic}} +{{/isEnum}} +{{/model}} +{{/models}} +end diff --git a/model_doc.mustache b/model_doc.mustache new file mode 100644 index 000000000000..68de5593f657 --- /dev/null +++ b/model_doc.mustache @@ -0,0 +1,9 @@ +{{#models}}{{#model}}# {{moduleName}}::{{classname}} + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{/vars}} + +{{/model}}{{/models}} diff --git a/model_test.mustache b/model_test.mustache new file mode 100644 index 000000000000..f0e6b6c46e6e --- /dev/null +++ b/model_test.mustache @@ -0,0 +1,48 @@ +=begin +{{> api_info}} +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for {{moduleName}}::{{classname}} +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +{{#models}} +{{#model}} +describe '{{classname}}' do + before do + # run before each test + @instance = {{moduleName}}::{{classname}}.new + end + + after do + # run after each test + end + + describe 'test an instance of {{classname}}' do + it 'should create an instance of {{classname}}' do + expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) + end + end +{{#vars}} + describe 'test attribute "{{{name}}}"' do + it 'should work' do + {{#isEnum}} + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + # validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + # validator.allowable_values.each do |value| + # expect { @instance.{{name}} = value }.not_to raise_error + # end + {{/isEnum}} + {{^isEnum}} + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + {{/isEnum}} + end + end + +{{/vars}} +end +{{/model}} +{{/models}} diff --git a/partial_model_enum_class.mustache b/partial_model_enum_class.mustache new file mode 100644 index 000000000000..36cee9e79481 --- /dev/null +++ b/partial_model_enum_class.mustache @@ -0,0 +1,13 @@ + class {{classname}} + {{#allowableValues}}{{#enumVars}} + {{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}} + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + constantValues = {{classname}}.constants.select { |c| {{classname}}::const_get(c) == value } + raise "Invalid ENUM value #{value} for class #{{{classname}}}" if constantValues.empty? + value + end + end \ No newline at end of file diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache new file mode 100644 index 000000000000..eb91155ed065 --- /dev/null +++ b/partial_model_generic.mustache @@ -0,0 +1,279 @@ + {{#description}} + # {{{description}}} + {{/description}} + class {{classname}} + {{#vars}} + {{#description}} + # {{{description}}} + {{/description}} + attr_accessor :{{{name}}} + + {{/vars}} +{{#hasEnums}} + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + +{{/hasEnums}} + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + {{#vars}} + :'{{{name}}}' => :'{{{baseName}}}'{{#hasMore}},{{/hasMore}} + {{/vars}} + } + end + + # Attribute type mapping. + def self.openapi_types + { + {{#vars}} + :'{{{name}}}' => :'{{{dataType}}}'{{#hasMore}},{{/hasMore}} + {{/vars}} + } + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + return unless attributes.is_a?(Hash) + + # convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + {{#vars}} + + if attributes.has_key?(:'{{{baseName}}}') + {{#isListContainer}} + if (value = attributes[:'{{{baseName}}}']).is_a?(Array) + self.{{{name}}} = value + end + {{/isListContainer}} + {{#isMapContainer}} + if (value = attributes[:'{{{baseName}}}']).is_a?(Hash) + self.{{{name}}} = value + end + {{/isMapContainer}} + {{^isContainer}} + self.{{{name}}} = attributes[:'{{{baseName}}}'] + {{/isContainer}} + {{#defaultValue}} + else + self.{{{name}}} = {{{defaultValue}}} + {{/defaultValue}} + end + {{/vars}} + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + {{#vars}} + {{#required}} + if @{{{name}}}.nil? + invalid_properties.push('invalid value for "{{{name}}}", {{{name}}} cannot be nil.') + end + + {{/required}} + {{#hasValidation}} + {{#maxLength}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length > {{{maxLength}}} + invalid_properties.push('invalid value for "{{{name}}}", the character length must be smaller than or equal to {{{maxLength}}}.') + end + + {{/maxLength}} + {{#minLength}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length < {{{minLength}}} + invalid_properties.push('invalid value for "{{{name}}}", the character length must be great than or equal to {{{minLength}}}.') + end + + {{/minLength}} + {{#maximum}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} + invalid_properties.push('invalid value for "{{{name}}}", must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.') + end + + {{/maximum}} + {{#minimum}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} + invalid_properties.push('invalid value for "{{{name}}}", must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.') + end + + {{/minimum}} + {{#pattern}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ Regexp.new({{{pattern}}}) + invalid_properties.push('invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.') + end + + {{/pattern}} + {{#maxItems}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length > {{{maxItems}}} + invalid_properties.push('invalid value for "{{{name}}}", number of items must be less than or equal to {{{maxItems}}}.' + end + + {{/maxItems}} + {{#minItems}} + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length < {{{minItems}}} + invalid_properties.push('invalid value for "{{{name}}}", number of items must be greater than or equal to {{{minItems}}}.' + end + + {{/minItems}} + {{/hasValidation}} + {{/vars}} + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + {{#vars}} + {{#required}} + return false if @{{{name}}}.nil? + {{/required}} + {{#isEnum}} + {{^isContainer}} + {{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + return false unless {{{name}}}_validator.valid?(@{{{name}}}) + {{/isContainer}} + {{/isEnum}} + {{#hasValidation}} + {{#maxLength}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length > {{{maxLength}}} + {{/maxLength}} + {{#minLength}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length < {{{minLength}}} + {{/minLength}} + {{#maximum}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} + {{/maximum}} + {{#minimum}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} + {{/minimum}} + {{#pattern}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ Regexp.new({{{pattern}}}) + {{/pattern}} + {{#maxItems}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length > {{{maxItems}}} + {{/maxItems}} + {{#minItems}} + return false if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length < {{{minItems}}} + {{/minItems}} + {{/hasValidation}} + {{/vars}} + true + end + + {{#vars}} + {{#isEnum}} + {{^isContainer}} + # Custom attribute writer method checking allowed values (enum). + # @param [Object] {{{name}}} Object to be assigned + def {{{name}}}=({{{name}}}) + validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + unless validator.valid?({{{name}}}) + fail ArgumentError, 'invalid value for "{{{name}}}", must be one of #{validator.allowable_values}.' + end + @{{{name}}} = {{{name}}} + end + + {{/isContainer}} + {{/isEnum}} + {{^isEnum}} + {{#hasValidation}} + # Custom attribute writer method with validation + # @param [Object] {{{name}}} Value to be assigned + def {{{name}}}=({{{name}}}) + {{#required}} + if {{{name}}}.nil? + fail ArgumentError, '{{{name}}} cannot be nil' + end + + {{/required}} + {{#maxLength}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.to_s.length > {{{maxLength}}} + fail ArgumentError, 'invalid value for "{{{name}}}", the character length must be smaller than or equal to {{{maxLength}}}.' + end + + {{/maxLength}} + {{#minLength}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.to_s.length < {{{minLength}}} + fail ArgumentError, 'invalid value for "{{{name}}}", the character length must be great than or equal to {{{minLength}}}.' + end + + {{/minLength}} + {{#maximum}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} + fail ArgumentError, 'invalid value for "{{{name}}}", must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.' + end + + {{/maximum}} + {{#minimum}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} + fail ArgumentError, 'invalid value for "{{{name}}}", must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.' + end + + {{/minimum}} + {{#pattern}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} !~ Regexp.new({{{pattern}}}) + fail ArgumentError, 'invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.' + end + + {{/pattern}} + {{#maxItems}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.length > {{{maxItems}}} + fail ArgumentError, 'invalid value for "{{{name}}}", number of items must be less than or equal to {{{maxItems}}}.' + end + + {{/maxItems}} + {{#minItems}} + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.length < {{{minItems}}} + fail ArgumentError, 'invalid value for "{{{name}}}", number of items must be greater than or equal to {{{minItems}}}.' + end + + {{/minItems}} + @{{{name}}} = {{{name}}} + end + + {{/hasValidation}} + {{/isEnum}} + {{/vars}} + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class{{#vars}} && + {{name}} == o.{{name}}{{/vars}} + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Fixnum] Hash code + def hash + [{{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}].hash + end + +{{> base_object}} + end \ No newline at end of file diff --git a/rspec.mustache b/rspec.mustache new file mode 100644 index 000000000000..83e16f804474 --- /dev/null +++ b/rspec.mustache @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/rubocop.mustache b/rubocop.mustache new file mode 100644 index 000000000000..9bc9d341d8b6 --- /dev/null +++ b/rubocop.mustache @@ -0,0 +1,154 @@ +# 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 + # 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 + Exclude: + - '**/templates/**/*' + - '**/vendor/**/*' + - 'actionpack/lib/action_dispatch/journey/parser.rb' + +# Prefer &&/|| over and/or. +Style/AndOr: + Enabled: true + +# Do not use braces for hash literals when they are the last argument of a +# method call. +Style/BracesAroundHashParameters: + Enabled: true + EnforcedStyle: context_dependent + +# Align `when` with `case`. +Layout/CaseIndentation: + Enabled: true + +# Align comments with method definitions. +Layout/CommentIndentation: + Enabled: true + +Layout/ElseAlignment: + Enabled: true + +Layout/EmptyLineAfterMagicComment: + Enabled: true + +# In a regular class definition, no empty lines around the body. +Layout/EmptyLinesAroundClassBody: + Enabled: true + +# In a regular method definition, no empty lines around the body. +Layout/EmptyLinesAroundMethodBody: + Enabled: true + +# In a regular module definition, no empty lines around the body. +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +Layout/FirstParameterIndentation: + Enabled: true + +# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. +Style/HashSyntax: + Enabled: false + +# Method definitions after `private` or `protected` isolated calls need one +# extra level of indentation. +Layout/IndentationConsistency: + Enabled: true + EnforcedStyle: rails + +# Two spaces, no tabs (for indentation). +Layout/IndentationWidth: + Enabled: true + +Layout/LeadingCommentSpace: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +Style/DefWithParentheses: + Enabled: true + +# Defining a method with parameters needs parentheses. +Style/MethodDefParentheses: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: false + EnforcedStyle: always + +# Use `foo {}` not `foo{}`. +Layout/SpaceBeforeBlockBraces: + Enabled: true + +# Use `foo { bar }` not `foo {bar}`. +Layout/SpaceInsideBlockBraces: + Enabled: true + +# Use `{ a: 1 }` not `{a:1}`. +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + +Layout/SpaceInsideParens: + Enabled: true + +# Check quotes usage according to lint rule below. +#Style/StringLiterals: +# Enabled: true +# EnforcedStyle: single_quotes + +# Detect hard tabs, no hard tabs. +Layout/Tab: + Enabled: true + +# Blank lines should not have any spaces. +Layout/TrailingBlankLines: + Enabled: true + +# No trailing whitespace. +Layout/TrailingWhitespace: + Enabled: false + +# Use quotes for string literals when they are enough. +Style/UnneededPercentQ: + Enabled: true + +# Align `end` with the matching keyword or starting expression except for +# assignments, where it should be aligned with the LHS. +Lint/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: variable + AutoCorrect: true + +# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. +Lint/RequireParentheses: + Enabled: true + +Style/RedundantReturn: + Enabled: true + AllowMultipleReturnValues: true + +Style/Semicolon: + Enabled: true + AllowAsExpressionSeparator: true diff --git a/spec_helper.mustache b/spec_helper.mustache new file mode 100644 index 000000000000..8f4bb7541658 --- /dev/null +++ b/spec_helper.mustache @@ -0,0 +1,103 @@ +=begin +{{> api_info}} +=end + +# load the gem +require '{{{gemName}}}' + +# The following was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/version.mustache b/version.mustache new file mode 100644 index 000000000000..3ed97bceab3c --- /dev/null +++ b/version.mustache @@ -0,0 +1,7 @@ +=begin +{{> api_info}} +=end + +module {{moduleName}} + VERSION = '{{gemVersion}}' +end From dd1680e5f18e7e16a6ef1487701f0ff6ef72cd11 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Aug 2018 22:00:50 +0800 Subject: [PATCH 02/86] [Ruby] Better handling of operationID starting with a number (#719) * better handling of operationId starting with numbers in Ruby * update Rubocop to use Layout --- rubocop.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.mustache b/rubocop.mustache index 9bc9d341d8b6..98c7e3c7e516 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -136,7 +136,7 @@ Style/UnneededPercentQ: # Align `end` with the matching keyword or starting expression except for # assignments, where it should be aligned with the LHS. -Lint/EndAlignment: +Layout/EndAlignment: Enabled: true EnforcedStyleAlignWith: variable AutoCorrect: true From 43c150b4f0d33ec46ff765dec143e9f3d0478154 Mon Sep 17 00:00:00 2001 From: David van Laatum Date: Fri, 3 Aug 2018 01:32:09 +0930 Subject: [PATCH 03/86] #714 prevent throwing another exception if the request fails eg connection reset (#715) * prevent throwing another exception if the request fails eg connection reset * prevent throwing another exception if the request fails eg connection reset --- api_client.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_client.mustache b/api_client.mustache index 33feac7acdf0..31ed22373a57 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -238,7 +238,7 @@ module {{moduleName}} tempfile.write(chunk) end request.on_complete do |response| - tempfile.close + tempfile.close if tempfile @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ From e9c75dea1d1fb5e8dfaeabcab7f0db48f5d14704 Mon Sep 17 00:00:00 2001 From: Yusuke Iinuma Date: Fri, 10 Aug 2018 18:25:22 +0900 Subject: [PATCH 04/86] [Ruby] Fix method split (#780) * Fix methods split for readable * Recreate sample --- api.mustache | 1 + 1 file changed, 1 insertion(+) diff --git a/api.mustache b/api.mustache index aef0fbb24c99..b65c0578a175 100644 --- a/api.mustache +++ b/api.mustache @@ -186,6 +186,7 @@ module {{moduleName}} end return data, status_code, headers end + {{/operation}} end {{/operations}} From 6d8f1a807351529f019b38efb7fed89011c836fa Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 5 Sep 2018 06:59:16 +0700 Subject: [PATCH 05/86] Generate a Gemfile.lock for the Ruby client, to keep versions consistent when running automated tests (#966) --- Gemfile.lock.mustache | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Gemfile.lock.mustache diff --git a/Gemfile.lock.mustache b/Gemfile.lock.mustache new file mode 100644 index 000000000000..1c4722811279 --- /dev/null +++ b/Gemfile.lock.mustache @@ -0,0 +1,69 @@ +PATH + remote: . + specs: + {{gemName}}{{^gemName}}{{{appName}}}{{/gemName}} ({{gemVersion}}) + json (~> 2.1, >= 2.1.0) + typhoeus (~> 1.0, >= 1.0.1) + +GEM + remote: https://rubygems.org/ + specs: + ZenTest (4.11.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + autotest (4.4.6) + ZenTest (>= 4.4.1) + autotest-fsevent (0.2.13) + sys-uname + autotest-growl (0.2.16) + autotest-rails-pure (4.1.2) + crack (0.4.3) + safe_yaml (~> 1.0.0) + diff-lcs (1.3) + ethon (0.11.0) + ffi (>= 1.3.0) + ffi (1.9.25) + hashdiff (0.3.7) + json (2.1.0) + public_suffix (3.0.3) + rake (12.0.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + safe_yaml (1.0.4) + sys-uname (1.0.3) + ffi (>= 1.0.0) + typhoeus (1.3.0) + ethon (>= 0.9.0) + vcr (3.0.3) + webmock (1.24.6) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff + +PLATFORMS + ruby + +DEPENDENCIES + autotest (~> 4.4, >= 4.4.6) + autotest-fsevent (~> 0.2, >= 0.2.12) + autotest-growl (~> 0.2, >= 0.2.16) + autotest-rails-pure (~> 4.1, >= 4.1.2) + {{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}! + rake (~> 12.0.0) + rspec (~> 3.6, >= 3.6.0) + vcr (~> 3.0, >= 3.0.1) + webmock (~> 1.24, >= 1.24.3) + +BUNDLED WITH + 1.16.1 From f30466e2813c38e421f3aefe49fca4d2f9bddf9f Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 6 Sep 2018 17:19:31 +0700 Subject: [PATCH 06/86] Added pry-byebug to debug Ruby client (#979) --- Gemfile.lock.mustache | 10 ++++++++++ Gemfile.mustache | 1 + 2 files changed, 11 insertions(+) diff --git a/Gemfile.lock.mustache b/Gemfile.lock.mustache index 1c4722811279..bb7eb9d3f799 100644 --- a/Gemfile.lock.mustache +++ b/Gemfile.lock.mustache @@ -17,6 +17,8 @@ GEM sys-uname autotest-growl (0.2.16) autotest-rails-pure (4.1.2) + byebug (10.0.2) + coderay (1.1.2) crack (0.4.3) safe_yaml (~> 1.0.0) diff-lcs (1.3) @@ -25,6 +27,13 @@ GEM ffi (1.9.25) hashdiff (0.3.7) json (2.1.0) + method_source (0.9.0) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-byebug (3.6.0) + byebug (~> 10.0) + pry (~> 0.10) public_suffix (3.0.3) rake (12.0.0) rspec (3.8.0) @@ -60,6 +69,7 @@ DEPENDENCIES autotest-growl (~> 0.2, >= 0.2.16) autotest-rails-pure (~> 4.1, >= 4.1.2) {{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}! + pry-byebug rake (~> 12.0.0) rspec (~> 3.6, >= 3.6.0) vcr (~> 3.0, >= 3.0.1) diff --git a/Gemfile.mustache b/Gemfile.mustache index d255a3ab238d..01ba313fe124 100644 --- a/Gemfile.mustache +++ b/Gemfile.mustache @@ -4,4 +4,5 @@ gemspec group :development, :test do gem 'rake', '~> 12.0.0' + gem 'pry-byebug' end From 380b5c05deb1c351c2e943b4a75cc79b532630f8 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 20 Sep 2018 19:31:47 +0800 Subject: [PATCH 07/86] add nullable to Ruby client (#1059) --- api.mustache | 2 ++ partial_model_generic.mustache | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/api.mustache b/api.mustache index b65c0578a175..568f9c1903c0 100644 --- a/api.mustache +++ b/api.mustache @@ -43,6 +43,7 @@ module {{moduleName}} @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' end {{#allParams}} + {{^isNullable}} {{#required}} # verify the required parameter '{{paramName}}' is set if @api_client.config.client_side_validation && {{{paramName}}}.nil? @@ -57,6 +58,7 @@ module {{moduleName}} {{/isContainer}} {{/isEnum}} {{/required}} + {{/isNullable}} {{^required}} {{#isEnum}} {{#collectionFormat}} diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index eb91155ed065..576a8444f02f 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -87,12 +87,14 @@ def list_invalid_properties invalid_properties = Array.new {{#vars}} + {{^isNullable}} {{#required}} if @{{{name}}}.nil? invalid_properties.push('invalid value for "{{{name}}}", {{{name}}} cannot be nil.') end {{/required}} + {{/isNullable}} {{#hasValidation}} {{#maxLength}} if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length > {{{maxLength}}} @@ -145,9 +147,11 @@ # @return true if the model is valid def valid? {{#vars}} + {{^isNullable}} {{#required}} return false if @{{{name}}}.nil? {{/required}} + {{/isNullable}} {{#isEnum}} {{^isContainer}} {{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) @@ -201,12 +205,14 @@ # Custom attribute writer method with validation # @param [Object] {{{name}}} Value to be assigned def {{{name}}}=({{{name}}}) + {{^isNullable}} {{#required}} if {{{name}}}.nil? fail ArgumentError, '{{{name}}} cannot be nil' end {{/required}} + {{/isNullable}} {{#maxLength}} if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.to_s.length > {{{maxLength}}} fail ArgumentError, 'invalid value for "{{{name}}}", the character length must be smaller than or equal to {{{maxLength}}}.' From 3fb51475d004c95e1d0042f997487800ad45b044 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 22 Oct 2018 12:52:52 +0800 Subject: [PATCH 08/86] Add "servers" support to Ruby API client (#1280) * update ruby samples with OAS3 spec * add server support to ruby api client * minor format change * minor format fix, skip form models * better exception and add test for invaid value * remove exception test code --- configuration.mustache | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/configuration.mustache b/configuration.mustache index 7c7e1d82dc5a..dcfb00042289 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -219,5 +219,70 @@ module {{moduleName}} {{/authMethods}} } end + + # Returns an array of Server setting + def server_settings + [ + {{#servers}} + { + url: "{{{url}}}", + description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + {{#variables}} + {{#-first}} + variables: { + {{/-first}} + {{{name}}}: { + description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + default_value: "{{{defaultValue}}}", + {{#enumValues}} + {{#-first}} + enum_values: [ + {{/-first}} + "{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ] + {{/-last}} + {{/enumValues}} + }{{^-last}},{{/-last}} + {{#-last}} + } + {{/-last}} + {{/variables}} + }{{^-last}},{{/-last}} + {{/servers}} + ] + end + + # Returns URL based on server settings + # + # @param index array index of the server settings + # @param variables hash of variable and the corresponding value + def server_url(index, variables = {}) + servers = server_settings + + # check array index out of bound + if (index < 0 || index > servers.size) + fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + end + + server = servers[index] + url = server[:url] + + # go through variable and assign a value + server[:variables].each do |name, variable| + if variables.key?(name) + if (server[:variables][name][:enum_values].include? variables[name]) + url.gsub! "{" + name.to_s + "}", variables[name] + else + fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." + end + else + # use default value + url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] + end + end + + url + end end end From 19b126ba88bde19eac11c120dee2f3ae7f8db3a0 Mon Sep 17 00:00:00 2001 From: Guy Gershoni Date: Wed, 7 Nov 2018 15:08:23 +1100 Subject: [PATCH 09/86] Added tests and fix for issue #1392. Fix regex generated in Ruby client. (#1393) * Added tests and fix for issue #1392. Param validation with regex not recognizing \d correctly in Ruby client. * Added generated files to pass ./bin/utils/ensure-up-to-date which is run by circleci --- Gemfile.lock.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock.mustache b/Gemfile.lock.mustache index bb7eb9d3f799..6ba95d4e7a4e 100644 --- a/Gemfile.lock.mustache +++ b/Gemfile.lock.mustache @@ -13,7 +13,7 @@ GEM public_suffix (>= 2.0.2, < 4.0) autotest (4.4.6) ZenTest (>= 4.4.1) - autotest-fsevent (0.2.13) + autotest-fsevent (0.2.14) sys-uname autotest-growl (0.2.16) autotest-rails-pure (4.1.2) From 1d86c8ab063715a44b0c9155c8f261cad34122a7 Mon Sep 17 00:00:00 2001 From: meganemura Date: Mon, 12 Nov 2018 15:26:05 +0900 Subject: [PATCH 10/86] Fix return_type parameter examples in ruby-client (#1399) * Fix return_type parameter examples * $ bin/openapi3/ruby-client-petstore.sh --- api_client.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_client.mustache b/api_client.mustache index 31ed22373a57..03b8ca31f928 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -137,7 +137,7 @@ module {{moduleName}} # Deserialize the response to the given return type. # # @param [Response] response HTTP response - # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]" + # @param [String] return_type some examples: "User", "Array", "Hash" def deserialize(response, return_type) body = response.body From c368bc828539a19420e9eb05ca5d04e544245250 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 7 Dec 2018 00:30:20 +0800 Subject: [PATCH 11/86] Better OpenAPI spec v3 support: allOf, anyOf, oneOf (#1360) * add oneOf support to Ruby * add anyOf support to ruby client * add discriminator support to ruby client * fix typo * update samples, fix NPE * better format in ruby generator * fix test cases, disable mapping test * fix update script, update samples * add test, fix mapping * update exit code * reenabled discriminator test * remove duplicated properties * add test for duplicated properties * update samples, add new spec * fix ruby test cases * fix hasMore after removing duplicates * refactor method, comment out haskell client test * fix hasMore and update samples * fix parent detection * fix discriminator check * [haskell-http-client] need to use {{vars}}{{required}} instead of {{requiredVars}} * remove deprecated methods in default codegen (#1031) * regenerate samples * remove commented code --- base_object.mustache | 7 ++- partial_model_generic.mustache | 101 +++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 7 deletions(-) diff --git a/base_object.mustache b/base_object.mustache index 815f5078fc7e..faef2ae199e1 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -3,6 +3,9 @@ # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + {{#parent}} + super(attributes) + {{/parent}} self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -75,7 +78,7 @@ # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -100,4 +103,4 @@ else value end - end \ No newline at end of file + end diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 576a8444f02f..f6082b111ab9 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -1,7 +1,7 @@ {{#description}} # {{{description}}} {{/description}} - class {{classname}} + class {{classname}}{{#parent}} < {{{.}}}{{/parent}} {{#vars}} {{#description}} # {{{description}}} @@ -51,6 +51,54 @@ } end + {{#anyOf}} + {{#-first}} + # List of class defined in anyOf (OpenAPI v3) + def self.openapi_any_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/anyOf}} + {{#oneOf}} + {{#-first}} + # List of class defined in oneOf (OpenAPI v3) + def self.openapi_one_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/oneOf}} + {{#allOf}} + {{#-first}} + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/allOf}} + {{#discriminator}} + {{#propertyName}} + # discriminator's property name in OpenAPI v3 + def self.openapi_discriminator_name + :'{{{.}}}' + end + + {{/propertyName}} + {{/discriminator}} # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -58,6 +106,11 @@ # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + {{#parent}} + + # call parent's initialize + super(attributes) + {{/parent}} {{#vars}} if attributes.has_key?(:'{{{baseName}}}') @@ -85,7 +138,7 @@ # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = {{^parent}}Array.new{{/parent}}{{#parent}}super{{/parent}} {{#vars}} {{^isNullable}} {{#required}} @@ -182,7 +235,45 @@ {{/minItems}} {{/hasValidation}} {{/vars}} - true + {{#anyOf}} + {{#-first}} + _any_of_found = false + openapi_any_of.each do |_class| + _any_of = {{moduleName}}.const_get(_class).new + _any_of.build_from_hash(self.to_hash) + if _any_of.valid? + _any_of_found = true + end + end + + if !_any_of_found? + return false + end + + {{/-first}} + {{/anyOf}} + {{#oneOf}} + {{#-first}} + _one_of_found = false + openapi_one_of.each do |_class| + _one_of = {{moduleName}}.const_get(_class).new + _one_of.build_from_hash(self.to_hash) + if _one_of.valid? + if _one_of_found? + return false + else + _one_of_found = true + end + end + end + + if !_one_of_found? + return false + end + + {{/-first}} + {{/oneOf}} + true{{#parent}} && super{{/parent}} end {{#vars}} @@ -266,7 +357,7 @@ def ==(o) return true if self.equal?(o) self.class == o.class{{#vars}} && - {{name}} == o.{{name}}{{/vars}} + {{name}} == o.{{name}}{{/vars}}{{#parent}} && super(o){{/parent}} end # @see the `==` method @@ -282,4 +373,4 @@ end {{> base_object}} - end \ No newline at end of file + end From 8d21297dda9dac3670440673ff989f693e517bcb Mon Sep 17 00:00:00 2001 From: meganemura Date: Sat, 15 Dec 2018 17:24:03 +0900 Subject: [PATCH 12/86] Improve model class of ruby-client (#1670) * Add Model.build_from_hash * Use Model.build_from_hash instead of Model.new.build_from_hash * Update sample for ruby-client * Update sample for openapi3 ruby-client --- api_client.mustache | 4 +--- base_object.mustache | 10 ++++++++-- partial_model_enum_class.mustache | 9 ++++++++- partial_model_generic.mustache | 6 ++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index 03b8ca31f928..02dfd6703a9d 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -204,9 +204,7 @@ module {{moduleName}} end else # models, e.g. Pet - {{moduleName}}.const_get(return_type).new.tap do |model| - model.build_from_hash data - end + {{moduleName}}.const_get(return_type).build_from_hash(data) end end diff --git a/base_object.mustache b/base_object.mustache index faef2ae199e1..9ebcde2c6c1b 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -1,3 +1,10 @@ + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself @@ -58,8 +65,7 @@ end end else # model - temp_model = {{moduleName}}.const_get(type).new - temp_model.build_from_hash(value) + {{moduleName}}.const_get(type).build_from_hash(value) end end diff --git a/partial_model_enum_class.mustache b/partial_model_enum_class.mustache index 36cee9e79481..797bab82ab3d 100644 --- a/partial_model_enum_class.mustache +++ b/partial_model_enum_class.mustache @@ -2,6 +2,13 @@ {{#allowableValues}}{{#enumVars}} {{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}} + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + # Builds the enum from string # @param [String] The enum value in the form of the string # @return [String] The enum value @@ -10,4 +17,4 @@ raise "Invalid ENUM value #{value} for class #{{{classname}}}" if constantValues.empty? value end - end \ No newline at end of file + end diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index f6082b111ab9..17755675e7e0 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -239,8 +239,7 @@ {{#-first}} _any_of_found = false openapi_any_of.each do |_class| - _any_of = {{moduleName}}.const_get(_class).new - _any_of.build_from_hash(self.to_hash) + _any_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash) if _any_of.valid? _any_of_found = true end @@ -256,8 +255,7 @@ {{#-first}} _one_of_found = false openapi_one_of.each do |_class| - _one_of = {{moduleName}}.const_get(_class).new - _one_of.build_from_hash(self.to_hash) + _one_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash) if _one_of.valid? if _one_of_found? return false From 7b14de902f8bccb4a86ea1ac9af93ba99414801d Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 5 Jan 2019 09:39:10 +0800 Subject: [PATCH 13/86] Fix various typos in the templates (Ruby, C#) (#1803) * Fix typos * update petstore samples --- base_object.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_object.mustache b/base_object.mustache index 9ebcde2c6c1b..4a28047738a2 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -15,7 +15,7 @@ {{/parent}} self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i - # check to ensure the input is an array given that the the attribute + # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) From bbae8b15841b5661b658f2f43bd36832018c85ef Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 27 Jan 2019 21:18:20 +0800 Subject: [PATCH 14/86] fix index check, add test cases (#1993) --- configuration.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configuration.mustache b/configuration.mustache index dcfb00042289..d0d190ff2f5b 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -261,8 +261,8 @@ module {{moduleName}} servers = server_settings # check array index out of bound - if (index < 0 || index > servers.size) - fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + if (index < 0 || index >= servers.size) + fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" end server = servers[index] From 044ebec3e320c2ae3ee15f5aa44e81bd79e2b39b Mon Sep 17 00:00:00 2001 From: autopp Date: Wed, 6 Feb 2019 15:59:54 +0900 Subject: [PATCH 15/86] [Ruby] Use double-quote string to enable string interpolation (#2067) (#2068) --- partial_model_generic.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 17755675e7e0..af4381836cf8 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -282,7 +282,7 @@ def {{{name}}}=({{{name}}}) validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) unless validator.valid?({{{name}}}) - fail ArgumentError, 'invalid value for "{{{name}}}", must be one of #{validator.allowable_values}.' + fail ArgumentError, "invalid value for \"{{{name}}}\", must be one of #{validator.allowable_values}." end @{{{name}}} = {{{name}}} end From 6fe175c0ea8b01a39067f40d6a99954ea9181f2b Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Sun, 10 Feb 2019 09:29:34 +0900 Subject: [PATCH 16/86] [Ruby] Fix Ruby client to prevent Rubocop's rule violations (#2100) (#2102) * [Ruby] Delete empty lines and trailing newline in template to prevent Rubocop's rule violation (#2100) * [Ruby] update samples of Ruby client (#2100) --- api.mustache | 2 ++ base_object.mustache | 2 +- partial_model_enum_class.mustache | 2 +- partial_model_generic.mustache | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api.mustache b/api.mustache index 568f9c1903c0..a1e8832980bb 100644 --- a/api.mustache +++ b/api.mustache @@ -188,7 +188,9 @@ module {{moduleName}} end return data, status_code, headers end +{{^-last}} +{{/-last}} {{/operation}} end {{/operations}} diff --git a/base_object.mustache b/base_object.mustache index 4a28047738a2..7f38aaea89bf 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -109,4 +109,4 @@ else value end - end + end \ No newline at end of file diff --git a/partial_model_enum_class.mustache b/partial_model_enum_class.mustache index 797bab82ab3d..d6a4b269f396 100644 --- a/partial_model_enum_class.mustache +++ b/partial_model_enum_class.mustache @@ -17,4 +17,4 @@ raise "Invalid ENUM value #{value} for class #{{{classname}}}" if constantValues.empty? value end - end + end \ No newline at end of file diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index af4381836cf8..31b760491a2c 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -371,4 +371,4 @@ end {{> base_object}} - end + end \ No newline at end of file From 2d1b9f7c5504fa0a7e6c036bcabd143c9971a277 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Tue, 12 Feb 2019 01:32:36 +0900 Subject: [PATCH 17/86] [Ruby] Fix enum expansion in Ruby client (#2081) (#2104) * use double-quote string for enum value (#2081) * use enumVars in templates for Ruby client (#2081) * delete unnecessary line in enum model of Ruby client (#2081) * update samples of Ruby client (#2081) --- api.mustache | 15 +++++++++------ model_test.mustache | 2 +- partial_model_enum_class.mustache | 6 +++--- partial_model_generic.mustache | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/api.mustache b/api.mustache index a1e8832980bb..60d12f4d7052 100644 --- a/api.mustache +++ b/api.mustache @@ -52,8 +52,9 @@ module {{moduleName}} {{#isEnum}} {{^isContainer}} # verify enum value - if @api_client.config.client_side_validation && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) - fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" + allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] + if @api_client.config.client_side_validation && !allowable_values.include?({{{paramName}}}) + fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}" end {{/isContainer}} {{/isEnum}} @@ -62,13 +63,15 @@ module {{moduleName}} {{^required}} {{#isEnum}} {{#collectionFormat}} - if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(item) } - fail ArgumentError, 'invalid value for "{{{paramName}}}", must include one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| allowable_values.include?(item) } + fail ArgumentError, "invalid value for \"{{{paramName}}}\", must include one of #{allowable_values}" end {{/collectionFormat}} {{^collectionFormat}} - if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) - fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' + allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !allowable_values.include?(opts[:'{{{paramName}}}']) + fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}" end {{/collectionFormat}} {{/isEnum}} diff --git a/model_test.mustache b/model_test.mustache index f0e6b6c46e6e..47b8d53c3197 100644 --- a/model_test.mustache +++ b/model_test.mustache @@ -31,7 +31,7 @@ describe '{{classname}}' do it 'should work' do {{#isEnum}} # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers - # validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + # validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]) # validator.allowable_values.each do |value| # expect { @instance.{{name}} = value }.not_to raise_error # end diff --git a/partial_model_enum_class.mustache b/partial_model_enum_class.mustache index d6a4b269f396..4b8b5a0ffdae 100644 --- a/partial_model_enum_class.mustache +++ b/partial_model_enum_class.mustache @@ -1,7 +1,7 @@ - class {{classname}} - {{#allowableValues}}{{#enumVars}} - {{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}} + class {{classname}}{{#allowableValues}}{{#enumVars}} + {{{name}}} = {{{value}}}.freeze{{/enumVars}} +{{/allowableValues}} # Builds the enum from string # @param [String] The enum value in the form of the string # @return [String] The enum value diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 31b760491a2c..a35a18d965c8 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -207,7 +207,7 @@ {{/isNullable}} {{#isEnum}} {{^isContainer}} - {{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + {{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]) return false unless {{{name}}}_validator.valid?(@{{{name}}}) {{/isContainer}} {{/isEnum}} @@ -280,7 +280,7 @@ # Custom attribute writer method checking allowed values (enum). # @param [Object] {{{name}}} Object to be assigned def {{{name}}}=({{{name}}}) - validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) + validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]) unless validator.valid?({{{name}}}) fail ArgumentError, "invalid value for \"{{{name}}}\", must be one of #{validator.allowable_values}." end From ff150dd5023e436426b1143bfba98fd975efb247 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Mon, 18 Feb 2019 22:18:55 +0900 Subject: [PATCH 18/86] [Ruby] Fix regualr expression in error message (#2069) (#2139) * Fix usage of regular expression literals in Ruby client (#2069) * update samples of Ruby client (#2069) --- api.mustache | 5 +++-- partial_model_generic.mustache | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api.mustache b/api.mustache index 60d12f4d7052..f26a1887ba18 100644 --- a/api.mustache +++ b/api.mustache @@ -102,8 +102,9 @@ module {{moduleName}} {{/minimum}} {{#pattern}} - if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}}) - fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}." + pattern = Regexp.new({{{pattern}}}) + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ pattern + fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern #{pattern}." end {{/pattern}} diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index a35a18d965c8..b2bc8b5660e8 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -174,8 +174,9 @@ {{/minimum}} {{#pattern}} - if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ Regexp.new({{{pattern}}}) - invalid_properties.push('invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.') + pattern = Regexp.new({{{pattern}}}) + if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ pattern + invalid_properties.push("invalid value for \"{{{name}}}\", must conform to the pattern #{pattern}.") end {{/pattern}} @@ -327,8 +328,9 @@ {{/minimum}} {{#pattern}} - if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} !~ Regexp.new({{{pattern}}}) - fail ArgumentError, 'invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.' + pattern = Regexp.new({{{pattern}}}) + if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} !~ pattern + fail ArgumentError, "invalid value for \"{{{name}}}\", must conform to the pattern #{pattern}." end {{/pattern}} From 6be6d87acebf8118f634c00ae179bb024c1046ac Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 27 Feb 2019 03:38:20 +0800 Subject: [PATCH 19/86] [Ruby] various improvements (#2226) * add to_s in api error class * rename variable to align with code sample * fix initalize, better validation * update petstore samples * add code sample for model * add auto-generated travis file * improve error message * add travis file * uncomment to_s --- api_error.mustache | 19 +++++++++++++++++++ api_test.mustache | 4 ++-- model_doc.mustache | 9 +++++++++ partial_model_generic.mustache | 21 ++++++++++++++------- travis.mustache | 11 +++++++++++ 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 travis.mustache diff --git a/api_error.mustache b/api_error.mustache index b3320779b36e..6d1967b7ba4b 100644 --- a/api_error.mustache +++ b/api_error.mustache @@ -26,5 +26,24 @@ module {{moduleName}} super arg end end + + # Override to_s to display a friendly error message + def to_s + message + end + + def message + if @message.nil? + msg = "Error message: the server returns an error" + else + msg = @message + end + + msg += "\nHTTP status code: #{code}" if code + msg += "\nResponse headers: #{response_headers}" if response_headers + msg += "\nResponse body: #{response_body}" if response_body + + msg + end end end diff --git a/api_test.mustache b/api_test.mustache index ee3c6e18b555..84d72edbc9fa 100644 --- a/api_test.mustache +++ b/api_test.mustache @@ -11,7 +11,7 @@ require 'json' {{#operations}}describe '{{classname}}' do before do # run before each test - @instance = {{moduleName}}::{{classname}}.new + @api_instance = {{moduleName}}::{{classname}}.new end after do @@ -20,7 +20,7 @@ require 'json' describe 'test an instance of {{classname}}' do it 'should create an instance of {{classname}}' do - expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) + expect(@api_instance).to be_instance_of({{moduleName}}::{{classname}}) end end diff --git a/model_doc.mustache b/model_doc.mustache index 68de5593f657..ec7ebfbf02e2 100644 --- a/model_doc.mustache +++ b/model_doc.mustache @@ -6,4 +6,13 @@ Name | Type | Description | Notes {{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} {{/vars}} +## Code Sample + +```ruby +require '{{moduleName}}' + +instance = {{moduleName}}::{{classname}}.new({{#vars}}{{name}}: {{example}}{{^-last}}, + {{/-last}}{{/vars}}) +``` + {{/model}}{{/models}} diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index b2bc8b5660e8..64695edf5733 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -102,10 +102,17 @@ # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) - return unless attributes.is_a?(Hash) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `{{{moduleName}}}::{{{classname}}}` initialize method" + end - # convert string to symbol for hash key - attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `{{{moduleName}}}::{{{classname}}}`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } {{#parent}} # call parent's initialize @@ -113,19 +120,19 @@ {{/parent}} {{#vars}} - if attributes.has_key?(:'{{{baseName}}}') + if attributes.key?(:'{{{name}}}') {{#isListContainer}} - if (value = attributes[:'{{{baseName}}}']).is_a?(Array) + if (value = attributes[:'{{{name}}}']).is_a?(Array) self.{{{name}}} = value end {{/isListContainer}} {{#isMapContainer}} - if (value = attributes[:'{{{baseName}}}']).is_a?(Hash) + if (value = attributes[:'{{{name}}}']).is_a?(Hash) self.{{{name}}} = value end {{/isMapContainer}} {{^isContainer}} - self.{{{name}}} = attributes[:'{{{baseName}}}'] + self.{{{name}}} = attributes[:'{{{name}}}'] {{/isContainer}} {{#defaultValue}} else diff --git a/travis.mustache b/travis.mustache new file mode 100644 index 000000000000..7a5a32b4544d --- /dev/null +++ b/travis.mustache @@ -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 {{{gemName}}}.gemspec + - gem install ./{{{gemName}}}-{{{gemVersion}}}.gem From 358c5f8ad0828afcf0b1bac8b2c654b789ca1a03 Mon Sep 17 00:00:00 2001 From: ota42y Date: Mon, 4 Mar 2019 23:18:15 +0900 Subject: [PATCH 20/86] update ZenTest (#2289) * update ZenTest ZenTest 4.11.1 requires rubygems 2.x. But Ruby 2.6.0 include rubygems 3.x. So we can't use ruby client in Ruby 2.6.0. https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/ ZenTest 4.11.2 removed rubygems dependency so we should update. https://github.com/seattlerb/zentest/commit/1883b210aa3dc2377e2d3571f95a5e462c0e1ce7 * update ruby client sample --- Gemfile.lock.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock.mustache b/Gemfile.lock.mustache index 6ba95d4e7a4e..bf18a06ea838 100644 --- a/Gemfile.lock.mustache +++ b/Gemfile.lock.mustache @@ -8,7 +8,7 @@ PATH GEM remote: https://rubygems.org/ specs: - ZenTest (4.11.1) + ZenTest (4.11.2) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) autotest (4.4.6) From 2d89ebb9eaae4c2c73062d8bf66e4053e02bb628 Mon Sep 17 00:00:00 2001 From: ota42y Date: Wed, 13 Mar 2019 01:17:49 +0900 Subject: [PATCH 21/86] Outputs dataType to YARD tag (#2329) * output dataType to YARD tag YARD supports parameter type tag. https://www.rubydoc.info/gems/yard/file/docs/Tags.md#param We can use `dataType` as parameter type. So it's very useful to output `dataType`. * update samples --- api.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api.mustache b/api.mustache index f26a1887ba18..8bd17c2e2883 100644 --- a/api.mustache +++ b/api.mustache @@ -19,7 +19,7 @@ module {{moduleName}} {{#notes}} # {{{notes}}} {{/notes}} -{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} {{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] @@ -34,7 +34,7 @@ module {{moduleName}} {{#notes}} # {{notes}} {{/notes}} -{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers From 5a3ef52fb272d671b71f1d9b3f9d639d0bc8b6ac Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Sun, 17 Mar 2019 12:07:00 +0900 Subject: [PATCH 22/86] [Ruby] Fix type mapping for Ruby (#2385) (#2386) * maps 'boolean' to 'Boolean' in Ruby (#2385) * update Ruby client samples (#2385) --- api_client.mustache | 2 +- base_object.mustache | 2 +- base_object_spec.mustache | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index 02dfd6703a9d..116f1eacbf1c 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -181,7 +181,7 @@ module {{moduleName}} data.to_i when 'Float' data.to_f - when 'BOOLEAN' + when 'Boolean' data == true when 'DateTime' # parse date time (expecting ISO 8601 format) diff --git a/base_object.mustache b/base_object.mustache index 7f38aaea89bf..0a663ef944aa 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -44,7 +44,7 @@ value.to_i when :Float value.to_f - when :BOOLEAN + when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else diff --git a/base_object_spec.mustache b/base_object_spec.mustache index 50778a95a298..56425d65461e 100644 --- a/base_object_spec.mustache +++ b/base_object_spec.mustache @@ -24,8 +24,8 @@ class ArrayMapObject < Petstore::Category :pet_map => :'Hash', :int_arr_map => :'Hash>', :pet_arr_map => :'Hash>', - :boolean_true_arr => :'Array', - :boolean_false_arr => :'Array', + :boolean_true_arr => :'Array', + :boolean_false_arr => :'Array', } end end From 86cf5c5d6c9b39f4f66e9fb1f0ccabe46b703407 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Thu, 21 Mar 2019 23:00:08 +0900 Subject: [PATCH 23/86] Add RuboCop to Gemfile (#2464) * Add Rubocop * Update samples ./bin/openapi3/ruby-client-petstore.sh ./bin/ruby-client-petstore.sh --- Gemfile.mustache | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.mustache b/Gemfile.mustache index 01ba313fe124..69255e559f7c 100644 --- a/Gemfile.mustache +++ b/Gemfile.mustache @@ -5,4 +5,5 @@ gemspec group :development, :test do gem 'rake', '~> 12.0.0' gem 'pry-byebug' + gem 'rubocop', '~> 0.66.0' end From 84c2094de7c3305b4dd63d85132469117c1e9138 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Sat, 23 Mar 2019 19:48:10 +0900 Subject: [PATCH 24/86] [Ruby] Use Integer instead of Fixnum in Ruby client (#2475) (#2481) * use Integer instead of Fixnum in Ruby client (#2475) * update samples (#2475) --- api.mustache | 2 +- api_client.mustache | 2 +- partial_model_generic.mustache | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api.mustache b/api.mustache index 8bd17c2e2883..1eeac63818b7 100644 --- a/api.mustache +++ b/api.mustache @@ -37,7 +37,7 @@ module {{moduleName}} {{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} -{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers +{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' diff --git a/api_client.mustache b/api_client.mustache index 116f1eacbf1c..8e5b92e9e005 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -36,7 +36,7 @@ module {{moduleName}} # Call an API with given options. # - # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements: + # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: # the data deserialized from response body (could be nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 64695edf5733..65351bad6e5c 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -374,7 +374,7 @@ end # Calculates hash code according to all attributes. - # @return [Fixnum] Hash code + # @return [Integer] Hash code def hash [{{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}].hash end From 3f3892af1f5365917d71478c3a98fef34cc831b2 Mon Sep 17 00:00:00 2001 From: Alok Prateek Date: Mon, 25 Mar 2019 19:18:22 +0530 Subject: [PATCH 25/86] [#2441] Update documentation mustache templates for proper linting. (#2458) * [#2441] Update documentation mustache files for PHP client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for ruby client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for javascript client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for Java client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for GO client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for Rust client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for C# client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * [#2441] Update documentation mustache files for Android client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] Issues with generated markdown files as reported by markdownlint for node.js are: - MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time - MD002 first-heading-h1/first-header-h1 - First heading should be a top level heading - MD007 ul-indent - Unordered list indentation - MD009 no-trailing-spaces - Trailing spaces - MD010 no-hard-tabs - Hard tabs - MD011 no-reversed-links - Reversed link syntax - MD025 single-h1 - Multiple top level headings in the same document - MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines - MD032 blanks-around-lists - Lists should be surrounded by blank lines - MD040 fenced-code-language - Fenced code blocks should have a language specified - MD041 first-line-h1 - First line in file should be a top level heading * Update README.mustache * [#2441] Update documentation mustache files for Ada client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] * [#2441] Update documentation mustache files for Apex client This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] * [#2441] Update documentation mustache files for bash This commit fixes issues with Markdown/CommonMark parsing by linting and enforcing consistent style.[#2441] --- README.mustache | 10 ++++++++-- api_doc.mustache | 13 ++++++++----- model_doc.mustache | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.mustache b/README.mustache index 8703af147ad7..00f50d813403 100644 --- a/README.mustache +++ b/README.mustache @@ -33,6 +33,7 @@ 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/). @@ -58,6 +59,7 @@ ruby -Ilib script.rb ## Getting Started Please follow the [installation](#installation) procedure and then run the following code: + ```ruby # Load the gem require '{{{gemName}}}' @@ -120,13 +122,17 @@ Class | Method | HTTP request | Description {{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} {{#authMethods}}### {{name}} -{{#isApiKey}}- **Type**: API key +{{#isApiKey}} + +- **Type**: API key - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}}- **Type**: HTTP basic authentication {{/isBasic}} -{{#isOAuth}}- **Type**: OAuth +{{#isOAuth}} + +- **Type**: OAuth - **Flow**: {{flow}} - **Authorization URL**: {{authorizationUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} diff --git a/api_doc.mustache b/api_doc.mustache index 5f6f5bb5a5a9..960c0552dcf8 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -1,4 +1,5 @@ # {{moduleName}}::{{classname}}{{#description}} + {{description}}{{/description}} All URIs are relative to *{{basePath}}* @@ -10,7 +11,9 @@ Method | HTTP request | Description {{#operations}} {{#operation}} -# **{{operationId}}** + +## {{operationId}} + > {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} {{{summary}}}{{#notes}} @@ -18,6 +21,7 @@ Method | HTTP request | Description {{{notes}}}{{/notes}} ### Example + ```ruby # load the gem require '{{{gemName}}}' @@ -60,6 +64,7 @@ end ``` ### Parameters + {{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} Name | Type | Description | Notes ------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} @@ -76,10 +81,8 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} - - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} - - +- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} +- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} {{/operation}} {{/operations}} diff --git a/model_doc.mustache b/model_doc.mustache index ec7ebfbf02e2..2112d2bc6d71 100644 --- a/model_doc.mustache +++ b/model_doc.mustache @@ -1,6 +1,7 @@ {{#models}}{{#model}}# {{moduleName}}::{{classname}} ## Properties + Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- {{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} From 41fb68eb8a125127a249b7092e54f0582f4ae6d4 Mon Sep 17 00:00:00 2001 From: ota42y Date: Sun, 28 Apr 2019 18:44:24 +0900 Subject: [PATCH 26/86] Pass opts argument to api client in ruby-client (#2754) * Pass opts argument to api client in ruby-client We want to change the option when debugging, changing timeout to specific api, etc... So we want to merge and pass options to api client. * fix ruby-client * fix openapi ruby-client * fix typo * fix template --- api.mustache | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/api.mustache b/api.mustache index 1eeac63818b7..84833056569a 100644 --- a/api.mustache +++ b/api.mustache @@ -126,7 +126,7 @@ module {{moduleName}} local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} # query parameters - query_params = {} + query_params = opts[:query_params] || {} {{#queryParams}} {{#required}} query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} @@ -139,7 +139,7 @@ module {{moduleName}} {{/queryParams}} # header parameters - header_params = {} + header_params = opts[:header_params] || {} {{#hasProduces}} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) @@ -160,7 +160,7 @@ module {{moduleName}} {{/headerParams}} # form parameters - form_params = {} + form_params = opts[:form_params] || {} {{#formParams}} {{#required}} form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} @@ -173,20 +173,24 @@ module {{moduleName}} {{/formParams}} # http body (model) - {{^bodyParam}} - post_body = nil - {{/bodyParam}} - {{#bodyParam}} - post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) - {{/bodyParam}} - auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] - data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, + post_body = opts[:body] {{#bodyParam}}|| @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) {{/bodyParam}} + + # return_type + return_type = opts[:return_type] {{#returnType}}|| '{{{returnType}}}' {{/returnType}} + + # auth_names + auth_names = opts[:auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] + + new_options = opts.merge( :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, - :auth_names => auth_names{{#returnType}}, - :return_type => '{{{returnType}}}'{{/returnType}}) + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end From c354753d324e08e1fa8fc0b39484ed599fa0d721 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Mon, 13 May 2019 15:52:58 +0900 Subject: [PATCH 27/86] [Ruby] update TargetRubyVersion in .rubocop.yml to 2.4 (#2876) --- rubocop.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.mustache b/rubocop.mustache index 98c7e3c7e516..e9f19c082d9d 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -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 From ef15ed2c7fa7b3c33b992296d2511d320ec951a4 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 13 May 2019 15:59:59 +0800 Subject: [PATCH 28/86] Minor wording change (#2875) * better wording for version of openapi doc * update petstore samples --- api_info.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_info.mustache b/api_info.mustache index 207e8fb31c65..1b3f9cb5ac45 100644 --- a/api_info.mustache +++ b/api_info.mustache @@ -6,7 +6,7 @@ #{{{appDescription}}} {{/appDescription}} -{{#version}}OpenAPI spec version: {{version}}{{/version}} +{{#version}}The version of the OpenAPI document: {{version}}{{/version}} {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} Generated by: https://openapi-generator.tech OpenAPI Generator version: {{{generatorVersion}}} From 31494faaa117b89fc320508c88bbd07c4b5b4f71 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Wed, 15 May 2019 16:17:57 +0300 Subject: [PATCH 29/86] Add support of Bearer Basic Authorization to Ruby client (#2856) * Support for Bearer in Ruby Client * Update README.mustache * Update README.mustache * Update api_doc.mustache * Update api_doc.mustache * Update api_doc.mustache * samples * Uncommited changes * Formatting * More Formatting * Fomatting * More formatting * More formatting * Even more formatting * Even more formatting * More formatting * Even more formatting * More formatting * More formatting --- README.mustache | 13 +++++++++---- api_doc.mustache | 6 ++++-- configuration.mustache | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.mustache b/README.mustache index 00f50d813403..182bb34f4f50 100644 --- a/README.mustache +++ b/README.mustache @@ -65,10 +65,12 @@ Please follow the [installation](#installation) procedure and then run the follo require '{{{gemName}}}' {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}} # Setup authorization -{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}} # Configure HTTP basic authorization: {{{name}}} - config.username = 'YOUR USERNAME' - config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}} + config.username = 'YOUR_USERNAME' + config.password = 'YOUR_PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}} + # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} + config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} 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) @@ -128,7 +130,10 @@ Class | Method | HTTP request | Description - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} +{{^isBasicBearer}}- **Type**: HTTP basic authentication +{{/isBasicBearer}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} +{{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} diff --git a/api_doc.mustache b/api_doc.mustache index 960c0552dcf8..dc163725e163 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -27,10 +27,12 @@ Method | HTTP request | Description require '{{{gemName}}}' {{#hasAuthMethods}} # setup authorization -{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}} # Configure HTTP basic authorization: {{{name}}} config.username = 'YOUR USERNAME' - config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}} + config.password = 'YOUR PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}} + # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} + config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} 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) diff --git a/configuration.mustache b/configuration.mustache index d0d190ff2f5b..2f43306a3b9f 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -199,6 +199,7 @@ module {{moduleName}} }, {{/isApiKey}} {{#isBasic}} +{{^isBasicBearer}} '{{name}}' => { type: 'basic', @@ -206,6 +207,19 @@ module {{moduleName}} key: 'Authorization', value: basic_auth_token }, +{{/isBasicBearer}} +{{#isBasicBearer}} + '{{name}}' => + { + type: 'bearer', + in: 'header', + {{#bearerFormat}} + format: '{{{.}}}', + {{/bearerFormat}} + key: 'Authorization', + value: "Bearer #{access_token}" + }, +{{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} '{{name}}' => From 21b6bf636d2a33d4ef069764712cb7f9c83d61b5 Mon Sep 17 00:00:00 2001 From: Chris Couzens Date: Sun, 2 Jun 2019 16:24:30 +0100 Subject: [PATCH 30/86] Ruby client: escape path parameters (#3039) * Ruby client: escape path parameters Path parameters should be escaped when encoded into the path. In the path '/pet/{petId}' let's pretend petId is a string instead of a number. If the user uses "Bobby" as the petId then they correctly get the path '/pet/Bobby'. But if they put 'Bobby/Tables' as the petId then they used to get the path '/pet/Bobby/Tables' which will be interpreted by the server as a different route. Using CGI::Escape they now get '/pet/Bobby%2FTables' which is correct. * Ruby client- regenerate further files Thank you @autopp for noticing I needed to update `samples/openapi3/client/petstore/ruby`. Regenerated by running `bin/openapi3/ruby-client-petstore.sh`. PR #3039 --- api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api.mustache b/api.mustache index 84833056569a..c92659ff2b14 100644 --- a/api.mustache +++ b/api.mustache @@ -3,6 +3,7 @@ =end require 'uri' +require 'cgi' module {{moduleName}} {{#operations}} @@ -123,7 +124,7 @@ module {{moduleName}} {{/hasValidation}} {{/allParams}} # resource path - local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} + local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s)){{/pathParams}} # query parameters query_params = opts[:query_params] || {} From b45e7636bfe856da683fc7ac57de50f4fab1f76f Mon Sep 17 00:00:00 2001 From: Chris Couzens Date: Wed, 5 Jun 2019 11:54:23 +0100 Subject: [PATCH 31/86] Ruby: Avoid double escaping path items (#3093) `URI.encode` is obsolete. `CGI.escape`, `URI.encode_www_form` or `URI.encode_www_form_component` are recommended instead. https://ruby-doc.org/stdlib-2.6/libdoc/uri/rdoc/URI/Escape.html#method-i-escape URI.encode has different behaviour to CGI.escape: ```ruby URI.encode('hello/world?test%string') => "hello/world?test%25string" CGI.escape('hello/world?test%string') => "hello%2Fworld%3Ftest%25string" ``` I recently raised pull request #3039 201cbdce29cc6cdbbbe9efcb1afb250a05bc2ffd That pull request escapes path items at insertion. Before either pull request, the path item 'hello?world' would go into the URL as 'hello?world'. That behaviour was insecure as if an attacker could control the path item value, they could change the URL the application connected to. After #3039 'hello?world' would go in as 'hello%253Fworld'. This was safer than before, but it's still not correct. If I'd realised at the time, I would have made it correct at the time. What this pull request does is make it go in as 'hello%35world', which is correct. ApiClient::build_request_url was URI.encoding the whole path. This wasn't protecting against all undesirable characters in the path items, but was escaping % characters a 2nd time which was unhelpful. I have additionally removed URI.encode from Configuration::base_url as I can't see any benefit it could be bringing. There is no justification for it in the commit where it was originally added: 47c8597d36a9bc0983ba5c40e2489bb094f9f076 --- api.mustache | 1 - api_client.mustache | 3 +-- configuration.mustache | 5 +---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/api.mustache b/api.mustache index c92659ff2b14..1c5a053a9b97 100644 --- a/api.mustache +++ b/api.mustache @@ -2,7 +2,6 @@ {{> api_info}} =end -require 'uri' require 'cgi' module {{moduleName}} diff --git a/api_client.mustache b/api_client.mustache index 8e5b92e9e005..28c762416206 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -7,7 +7,6 @@ require 'json' require 'logger' require 'tempfile' require 'typhoeus' -require 'uri' module {{moduleName}} class ApiClient @@ -256,7 +255,7 @@ module {{moduleName}} def build_request_url(path) # Add leading and trailing slashes to path path = "/#{path}".gsub(/\/+/, '/') - URI.encode(@config.base_url + path) + @config.base_url + path end # Builds the HTTP request body diff --git a/configuration.mustache b/configuration.mustache index 2f43306a3b9f..3c0148fbd4d2 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -2,8 +2,6 @@ {{> api_info}} =end -require 'uri' - module {{moduleName}} class Configuration # Defines url scheme @@ -166,8 +164,7 @@ module {{moduleName}} end def base_url - url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') - URI.encode(url) + "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') end # Gets API key (with prefix if set). From 3c820e02c1cef6511d3c772d05c7345080b803dd Mon Sep 17 00:00:00 2001 From: Rhuan <283004+rhuanbarreto@users.noreply.github.com> Date: Wed, 19 Jun 2019 18:50:29 +0200 Subject: [PATCH 32/86] Fix rubocop obsolescence (#3175) * Update obsolete rubocop configuration * Update obsolete rubocop config * Update obsolete rubocop config --- rubocop.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.mustache b/rubocop.mustache index e9f19c082d9d..0ef33ce5e322 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -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 }. From 4bd05ff918dd590609aec02b7f51d37c119531b5 Mon Sep 17 00:00:00 2001 From: Chris Couzens Date: Mon, 24 Jun 2019 16:30:00 +0100 Subject: [PATCH 33/86] Ruby-client: Don't encode slashes if strict-spec false (#3204) URL-special characters such as /,?,% should be encoded when inside path parameters. I changed the Ruby-client to do so. https://github.com/OpenAPITools/openapi-generator/pull/3039 Unfortunately, some projects relied on slashes not being expanded within path paramters: https://github.com/OpenAPITools/openapi-generator/issues/3119 With this commit, these projects can now pass `--strict-spec false` to not have / converted to %2F. strict spec not specified: / -> %2F --strict-spec true: / -> %2F --strict-spec false: / -> / --- api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.mustache b/api.mustache index 1c5a053a9b97..bebf2fcae866 100644 --- a/api.mustache +++ b/api.mustache @@ -123,7 +123,7 @@ module {{moduleName}} {{/hasValidation}} {{/allParams}} # resource path - local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s)){{/pathParams}} + local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}} # query parameters query_params = opts[:query_params] || {} From cb396694351e660883f50f16022ff03ffc8d4f25 Mon Sep 17 00:00:00 2001 From: Dennis Kliban Date: Wed, 31 Jul 2019 23:08:34 -0400 Subject: [PATCH 34/86] 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. --- faraday_api_client.mustache | 393 ++++++++++++++++++++++++++++++++++++ faraday_gemspec.mustache | 38 ++++ 2 files changed, 431 insertions(+) create mode 100644 faraday_api_client.mustache create mode 100644 faraday_gemspec.mustache diff --git a/faraday_api_client.mustache b/faraday_api_client.mustache new file mode 100644 index 000000000000..bfe0ad907f3a --- /dev/null +++ b/faraday_api_client.mustache @@ -0,0 +1,393 @@ +=begin +{{> api_info}} +=end + +require 'date' +require 'faraday' +require 'json' +require 'logger' +require 'tempfile' + +module {{moduleName}} + class ApiClient + # The Configuration object holding settings to be used in the API client. + attr_accessor :config + + # Defines the headers to be used in HTTP requests of all API calls by default. + # + # @return [Hash] + attr_accessor :default_headers + + # Initializes the ApiClient + # @option config [Configuration] Configuration for initializing the object, default to Configuration.default + def initialize(config = Configuration.default) + @config = config + @user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/#{VERSION}/ruby{{/httpUserAgent}}" + @default_headers = { + 'Content-Type' => 'application/json', + 'User-Agent' => @user_agent + } + end + + def self.default + @@default ||= ApiClient.new + end + + # Call an API with given options. + # + # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. + def call_api(http_method, path, opts = {}) + 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 + 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 + + 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 + end + rescue Faraday::TimeoutError + fail ApiError.new('Connection timed out') + end + + if opts[:return_type] + data = deserialize(response, opts[:return_type]) + else + data = nil + end + return data, response.status, response.headers + end + + # Builds the HTTP request + # + # @param [String] http_method HTTP method/verb (e.g. POST) + # @param [String] path URL path (e.g. /account/new) + # @option opts [Hash] :header_params Header parameters + # @option opts [Hash] :query_params Query parameters + # @option opts [Hash] :form_params Query parameters + # @option opts [Object] :body HTTP body (JSON/XML) + # @return [Typhoeus::Request] A Typhoeus Request + def build_request(http_method, path, request, opts = {}) + url = build_request_url(path) + http_method = http_method.to_sym.downcase + + header_params = @default_headers.merge(opts[:header_params] || {}) + query_params = opts[:query_params] || {} + form_params = opts[:form_params] || {} + + update_params_for_auth! header_params, query_params, opts[:auth_names] + + # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) + _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 + + req_opts = { + :method => http_method, + :headers => header_params, + :params => query_params, + :params_encoding => @config.params_encoding, + :timeout => @config.timeout, + :ssl_verifypeer => @config.verify_ssl, + :ssl_verifyhost => _verify_ssl_host, + :sslcert => @config.cert_file, + :sslkey => @config.key_file, + :verbose => @config.debugging + } + + # set custom cert, if provided + req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert + + if [:post, :patch, :put, :delete].include?(http_method) + req_body = build_request_body(header_params, form_params, opts[:body]) + req_opts.update :body => req_body + if @config.debugging + @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" + end + end + request.headers = header_params + request.body = req_body + request.url path + request.params = query_params + download_file(request) if opts[:return_type] == 'File' + request + end + + # Check if the given MIME is a JSON MIME. + # JSON MIME examples: + # application/json + # application/json; charset=UTF8 + # APPLICATION/JSON + # */* + # @param [String] mime MIME + # @return [Boolean] True if the MIME is application/json + def json_mime?(mime) + (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil? + end + + # Deserialize the response to the given return type. + # + # @param [Response] response HTTP response + # @param [String] return_type some examples: "User", "Array", "Hash" + def deserialize(response, return_type) + body = response.body + + # handle file downloading - return the File instance processed in request callbacks + # note that response body is empty when the file is written in chunks in request on_body callback + return @tempfile if return_type == 'File' + + return nil if body.nil? || body.empty? + + # return response body directly for String return type + return body if return_type == 'String' + + # ensuring a default content type + content_type = response.headers['Content-Type'] || 'application/json' + + fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) + + begin + data = JSON.parse("[#{body}]", :symbolize_names => true)[0] + rescue JSON::ParserError => e + if %w(String Date DateTime).include?(return_type) + data = body + else + raise e + end + end + + convert_to_type data, return_type + end + + # Convert data to the given return type. + # @param [Object] data Data to be converted + # @param [String] return_type Return type + # @return [Mixed] Data in a particular type + def convert_to_type(data, return_type) + return nil if data.nil? + case return_type + when 'String' + data.to_s + when 'Integer' + data.to_i + when 'Float' + data.to_f + when 'Boolean' + data == true + when 'DateTime' + # parse date time (expecting ISO 8601 format) + DateTime.parse data + when 'Date' + # parse date time (expecting ISO 8601 format) + Date.parse data + when 'Object' + # generic object (usually a Hash), return directly + data + when /\AArray<(.+)>\z/ + # e.g. Array + sub_type = $1 + data.map { |item| convert_to_type(item, sub_type) } + when /\AHash\\z/ + # e.g. Hash + sub_type = $1 + {}.tap do |hash| + data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } + end + else + # models, e.g. Pet + {{moduleName}}.const_get(return_type).build_from_hash(data) + end + end + + # Save response body into a file in (the defined) temporary folder, using the filename + # from the "Content-Disposition" header if provided, otherwise a random filename. + # The response body is written to the file in chunks in order to handle files which + # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby + # process can use. + # + # @see Configuration#temp_folder_path + def download_file(request) + tempfile = nil + encoding = nil + request.on_headers do |response| + content_disposition = response.headers['Content-Disposition'] + if content_disposition && content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = response.body.encoding + tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile = tempfile + end + request.on_body do |chunk| + chunk.force_encoding(encoding) + tempfile.write(chunk) + end + request.on_complete do |response| + tempfile.close if tempfile + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + end + end + + # Sanitize filename by removing path. + # e.g. ../../sun.gif becomes sun.gif + # + # @param [String] filename the filename to be sanitized + # @return [String] the sanitized filename + def sanitize_filename(filename) + filename.gsub(/.*[\/\\]/, '') + end + + def build_request_url(path) + # Add leading and trailing slashes to path + path = "/#{path}".gsub(/\/+/, '/') + @config.base_url + path + end + + # Builds the HTTP request body + # + # @param [Hash] header_params Header parameters + # @param [Hash] form_params Query parameters + # @param [Object] body HTTP body (JSON/XML) + # @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' + data = {} + form_params.each do |key, value| + case value + when ::File, ::Tempfile + data[key] = Faraday::UploadIO.new(value.path, '') + when ::Array, nil + # let Faraday handle Array and nil parameters + data[key] = value + else + data[key] = value.to_s + end + end + elsif body + data = body.is_a?(String) ? body : body.to_json + else + data = nil + end + data + end + + # Update hearder and query params based on authentication settings. + # + # @param [Hash] header_params Header parameters + # @param [Hash] query_params Query parameters + # @param [String] auth_names Authentication scheme name + def update_params_for_auth!(header_params, query_params, auth_names) + Array(auth_names).each do |auth_name| + auth_setting = @config.auth_settings[auth_name] + next unless auth_setting + case auth_setting[:in] + when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] + when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] + else fail ArgumentError, 'Authentication token must be in `query` of `header`' + end + end + end + + # Sets user agent in HTTP header + # + # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) + def user_agent=(user_agent) + @user_agent = user_agent + @default_headers['User-Agent'] = @user_agent + end + + # Return Accept header based on an array of accepts provided. + # @param [Array] accepts array for Accept + # @return [String] the Accept header (e.g. application/json) + def select_header_accept(accepts) + return nil if accepts.nil? || accepts.empty? + # use JSON when present, otherwise use all of the provided + json_accept = accepts.find { |s| json_mime?(s) } + json_accept || accepts.join(',') + end + + # Return Content-Type header based on an array of content types provided. + # @param [Array] content_types array for Content-Type + # @return [String] the Content-Type header (e.g. application/json) + def select_header_content_type(content_types) + # use application/json by default + return 'application/json' if content_types.nil? || content_types.empty? + # use JSON when present, otherwise use the first one + json_content_type = content_types.find { |s| json_mime?(s) } + json_content_type || content_types.first + end + + # Convert object (array, hash, object, etc) to JSON string. + # @param [Object] model object to be converted into JSON string + # @return [String] JSON string representation of the object + def object_to_http_body(model) + return model if model.nil? || model.is_a?(String) + local_body = nil + if model.is_a?(Array) + local_body = model.map { |m| object_to_hash(m) } + else + local_body = object_to_hash(model) + end + local_body.to_json + end + + # Convert object(non-array) to hash. + # @param [Object] obj object to be converted into JSON string + # @return [String] JSON string representation of the object + def object_to_hash(obj) + if obj.respond_to?(:to_hash) + obj.to_hash + else + obj + end + end + + # Build parameter value according to the given collection format. + # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi + def build_collection_param(param, collection_format) + case collection_format + when :csv + param.join(',') + when :ssv + param.join(' ') + when :tsv + param.join("\t") + when :pipes + param.join('|') + when :multi + # return the array directly as typhoeus will handle it as expected + param + else + fail "unknown collection format: #{collection_format.inspect}" + end + end + end +end diff --git a/faraday_gemspec.mustache b/faraday_gemspec.mustache new file mode 100644 index 000000000000..09046b7f28e4 --- /dev/null +++ b/faraday_gemspec.mustache @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- + +=begin +{{> api_info}} +=end + +$:.push File.expand_path("../lib", __FILE__) +require "{{gemName}}/version" + +Gem::Specification.new do |s| + s.name = "{{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}" + s.version = {{moduleName}}::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["{{gemAuthor}}{{^gemAuthor}}OpenAPI-Generator{{/gemAuthor}}"] + s.email = ["{{gemAuthorEmail}}{{^gemAuthorEmail}}{{infoEmail}}{{/gemAuthorEmail}}"] + s.homepage = "{{gemHomepage}}{{^gemHomepage}}https://openapi-generator.tech{{/gemHomepage}}" + s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" + s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" + {{#gemLicense}} + s.license = '{{{gemLicense}}}' + {{/gemLicense}} + {{^gemLicense}} + s.license = "Unlicense" + {{/gemLicense}} + s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 1.9{{/gemRequiredRubyVersion}}" + + s.add_runtime_dependency 'faraday', '>= 0.14.0' + s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0' + + s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' + s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' + s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' + + s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } + s.test_files = `find spec/*`.split("\n") + s.executables = [] + s.require_paths = ["lib"] +end From 8ad711b0dcf08cf25ea50af90a2d5dd258abdc49 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 2 Aug 2019 07:00:29 +0800 Subject: [PATCH 35/86] [Ruby][Faraday] Various improvements (#3520) * update ruby faraday oas v2 samples * skip some default tests in faraday * add ruby faraday oas v3 client * add tests, fix url * add tests to CI * fix file upload * undo changes to ruby-client-petstore.sh * test faraday first * combine gemspec tempaltes * test ruby faraday in drone.io * use smaller image * update bundler * use official ruby image * skip bundler installation * skip autotest * install make * use different image * skip ruby tests in drone.io --- api_client_spec.mustache | 2 ++ faraday_api_client.mustache | 50 +++++++++++++++++++------------------ faraday_gemspec.mustache | 38 ---------------------------- gemspec.mustache | 5 ++++ 4 files changed, 33 insertions(+), 62 deletions(-) delete mode 100644 faraday_gemspec.mustache diff --git a/api_client_spec.mustache b/api_client_spec.mustache index b887b92f31a3..3e8d070ef9f7 100644 --- a/api_client_spec.mustache +++ b/api_client_spec.mustache @@ -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) } @@ -81,6 +82,7 @@ describe {{moduleName}}::ApiClient do end end +{{/isFaraday}} describe '#deserialize' do it "handles Array" do api_client = {{moduleName}}::ApiClient.new diff --git a/faraday_api_client.mustache b/faraday_api_client.mustache index bfe0ad907f3a..58b36c179d4f 100644 --- a/faraday_api_client.mustache +++ b/faraday_api_client.mustache @@ -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] @@ -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 @@ -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 diff --git a/faraday_gemspec.mustache b/faraday_gemspec.mustache deleted file mode 100644 index 09046b7f28e4..000000000000 --- a/faraday_gemspec.mustache +++ /dev/null @@ -1,38 +0,0 @@ -# -*- encoding: utf-8 -*- - -=begin -{{> api_info}} -=end - -$:.push File.expand_path("../lib", __FILE__) -require "{{gemName}}/version" - -Gem::Specification.new do |s| - s.name = "{{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}" - s.version = {{moduleName}}::VERSION - s.platform = Gem::Platform::RUBY - s.authors = ["{{gemAuthor}}{{^gemAuthor}}OpenAPI-Generator{{/gemAuthor}}"] - s.email = ["{{gemAuthorEmail}}{{^gemAuthorEmail}}{{infoEmail}}{{/gemAuthorEmail}}"] - s.homepage = "{{gemHomepage}}{{^gemHomepage}}https://openapi-generator.tech{{/gemHomepage}}" - s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" - s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" - {{#gemLicense}} - s.license = '{{{gemLicense}}}' - {{/gemLicense}} - {{^gemLicense}} - s.license = "Unlicense" - {{/gemLicense}} - s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 1.9{{/gemRequiredRubyVersion}}" - - s.add_runtime_dependency 'faraday', '>= 0.14.0' - s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0' - - s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' - s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' - s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' - - s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } - s.test_files = `find spec/*`.split("\n") - s.executables = [] - s.require_paths = ["lib"] -end diff --git a/gemspec.mustache b/gemspec.mustache index b77bbb503673..e4a486855c5d 100644 --- a/gemspec.mustache +++ b/gemspec.mustache @@ -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' From d7232a3db3a1f4fd091de4bfa12e00817a752d71 Mon Sep 17 00:00:00 2001 From: Dennis Kliban Date: Fri, 2 Aug 2019 00:20:16 -0400 Subject: [PATCH 36/86] Problem: faraday ruby client does not respect TLS settings (#3527) Solution: pass in tls settings to the faraday client --- faraday_api_client.mustache | 20 ++- faraday_configuration.mustache | 300 +++++++++++++++++++++++++++++++++ 2 files changed, 311 insertions(+), 9 deletions(-) create mode 100644 faraday_configuration.mustache diff --git a/faraday_api_client.mustache b/faraday_api_client.mustache index 58b36c179d4f..f628ffecf070 100644 --- a/faraday_api_client.mustache +++ b/faraday_api_client.mustache @@ -38,7 +38,15 @@ module {{moduleName}} # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: # the data deserialized from response body (could be nil), response status code and response headers. def call_api(http_method, path, opts = {}) - connection = Faraday.new(:url => config.base_url) do |conn| + ssl_options = { + :ca_file => @config.ssl_ca_file, + :verify => @config.ssl_verify, + :verify => @config.ssl_verify_mode, + :client_cert => @config.ssl_client_cert, + :client_key => @config.ssl_client_key + } + + connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn| conn.basic_auth(config.username, config.password) if opts[:header_params]["Content-Type"] == "multipart/form-data" conn.request :multipart @@ -46,6 +54,7 @@ module {{moduleName}} 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) @@ -98,8 +107,7 @@ module {{moduleName}} update_params_for_auth! header_params, query_params, opts[:auth_names] - # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) - _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 + req_opts = { :method => http_method, @@ -107,15 +115,9 @@ module {{moduleName}} :params => query_params, :params_encoding => @config.params_encoding, :timeout => @config.timeout, - :ssl_verifypeer => @config.verify_ssl, - :ssl_verifyhost => _verify_ssl_host, - :sslcert => @config.cert_file, - :sslkey => @config.key_file, :verbose => @config.debugging } - # set custom cert, if provided - req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert if [:post, :patch, :put, :delete].include?(http_method) req_body = build_request_body(header_params, form_params, opts[:body]) diff --git a/faraday_configuration.mustache b/faraday_configuration.mustache new file mode 100644 index 000000000000..67aaaf4f00f6 --- /dev/null +++ b/faraday_configuration.mustache @@ -0,0 +1,300 @@ +=begin +{{> api_info}} +=end + +module {{moduleName}} + class Configuration + # Defines url scheme + attr_accessor :scheme + + # Defines url host + attr_accessor :host + + # Defines url base path + attr_accessor :base_path + + # Defines API keys used with API Key authentications. + # + # @return [Hash] key: parameter name, value: parameter value (API key) + # + # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string) + # config.api_key['api_key'] = 'xxx' + attr_accessor :api_key + + # Defines API key prefixes used with API Key authentications. + # + # @return [Hash] key: parameter name, value: API key prefix + # + # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers) + # config.api_key_prefix['api_key'] = 'Token' + attr_accessor :api_key_prefix + + # Defines the username used with HTTP basic authentication. + # + # @return [String] + attr_accessor :username + + # Defines the password used with HTTP basic authentication. + # + # @return [String] + attr_accessor :password + + # Defines the access token (Bearer) used with OAuth2. + attr_accessor :access_token + + # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response + # details will be logged with `logger.debug` (see the `logger` attribute). + # Default to false. + # + # @return [true, false] + attr_accessor :debugging + + # Defines the logger used for debugging. + # Default to `Rails.logger` (when in Rails) or logging to STDOUT. + # + # @return [#debug] + attr_accessor :logger + + # Defines the temporary folder to store downloaded files + # (for API endpoints that have file response). + # Default to use `Tempfile`. + # + # @return [String] + attr_accessor :temp_folder_path + + # The time limit for HTTP request in seconds. + # Default to 0 (never times out). + attr_accessor :timeout + + # Set this to false to skip client side validation in the operation. + # Default to true. + # @return [true, false] + attr_accessor :client_side_validation + + # Set this to false to skip client side validation in the operation. + # Default to true. + # @return [true, false] + attr_accessor :client_side_validation + + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :ssl_verify + + ### TLS/SSL setting + # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html) + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + attr_accessor :ssl_verify_mode + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + attr_accessor :ssl_ca_file + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :ssl_client_cert + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :ssl_client_key + + # Set this to customize parameters encoding of array parameter with multi collectionFormat. + # Default to nil. + # + # @see The params_encoding option of Ethon. Related source code: + # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 + attr_accessor :params_encoding + + attr_accessor :inject_format + + attr_accessor :force_ending_format + + def initialize + @scheme = 'http' + @host = 'localhost' + @base_path = '' + @api_key = {} + @api_key_prefix = {} + @params_encoding = nil + @timeout = 0 + @client_side_validation = true + @ssl_verify = true + @ssl_verify_mode = nil + @ssl_ca_file = nil + @ssl_client_cert = nil + @ssl_client_key = nil + @debugging = false + @inject_format = false + @force_ending_format = false + @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + + yield(self) if block_given? + end + + # The default Configuration object. + def self.default + @@default ||= Configuration.new + end + + def configure + yield(self) if block_given? + end + + def scheme=(scheme) + # remove :// from scheme + @scheme = scheme.sub(/:\/\//, '') + end + + def host=(host) + # remove http(s):// and anything after a slash + @host = host.sub(/https?:\/\//, '').split('/').first + end + + def base_path=(base_path) + # Add leading and trailing slashes to base_path + @base_path = "/#{base_path}".gsub(/\/+/, '/') + @base_path = '' if @base_path == '/' + end + + def base_url + "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') + end + + # Gets API key (with prefix if set). + # @param [String] param_name the parameter name of API key auth + def api_key_with_prefix(param_name) + if @api_key_prefix[param_name] + "#{@api_key_prefix[param_name]} #{@api_key[param_name]}" + else + @api_key[param_name] + end + end + + # Gets Basic Auth token string + def basic_auth_token + 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") + end + + # Returns Auth Settings hash for api client. + def auth_settings + { +{{#authMethods}} +{{#isApiKey}} + '{{name}}' => + { + type: 'api_key', + in: {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}, + key: '{{keyParamName}}', + value: api_key_with_prefix('{{keyParamName}}') + }, +{{/isApiKey}} +{{#isBasic}} +{{^isBasicBearer}} + '{{name}}' => + { + type: 'basic', + in: 'header', + key: 'Authorization', + value: basic_auth_token + }, +{{/isBasicBearer}} +{{#isBasicBearer}} + '{{name}}' => + { + type: 'bearer', + in: 'header', + {{#bearerFormat}} + format: '{{{.}}}', + {{/bearerFormat}} + key: 'Authorization', + value: "Bearer #{access_token}" + }, +{{/isBasicBearer}} +{{/isBasic}} +{{#isOAuth}} + '{{name}}' => + { + type: 'oauth2', + in: 'header', + key: 'Authorization', + value: "Bearer #{access_token}" + }, +{{/isOAuth}} +{{/authMethods}} + } + end + + # Returns an array of Server setting + def server_settings + [ + {{#servers}} + { + url: "{{{url}}}", + description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + {{#variables}} + {{#-first}} + variables: { + {{/-first}} + {{{name}}}: { + description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + default_value: "{{{defaultValue}}}", + {{#enumValues}} + {{#-first}} + enum_values: [ + {{/-first}} + "{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ] + {{/-last}} + {{/enumValues}} + }{{^-last}},{{/-last}} + {{#-last}} + } + {{/-last}} + {{/variables}} + }{{^-last}},{{/-last}} + {{/servers}} + ] + end + + # Returns URL based on server settings + # + # @param index array index of the server settings + # @param variables hash of variable and the corresponding value + def server_url(index, variables = {}) + servers = server_settings + + # check array index out of bound + if (index < 0 || index >= servers.size) + fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + end + + server = servers[index] + url = server[:url] + + # go through variable and assign a value + server[:variables].each do |name, variable| + if variables.key?(name) + if (server[:variables][name][:enum_values].include? variables[name]) + url.gsub! "{" + name.to_s + "}", variables[name] + else + fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." + end + else + # use default value + url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] + end + end + + url + end + end +end From 8ede101677a7195e4bdcba0ae666e673fd802fd9 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 2 Aug 2019 21:18:24 +0800 Subject: [PATCH 37/86] Use partial for Ruby HTTP libraries (#3539) * use partial for ruby http libraries * fix isFaraday * add back client side validation switch * remove blank lines --- configuration.mustache | 50 +++++++-------------- configuration_tls_faraday_partial.mustache | 29 ++++++++++++ configuration_tls_typhoeus_partial.mustache | 34 ++++++++++++++ faraday_api_client.mustache | 3 -- 4 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 configuration_tls_faraday_partial.mustache create mode 100644 configuration_tls_typhoeus_partial.mustache diff --git a/configuration.mustache b/configuration.mustache index 3c0148fbd4d2..72f6fe90e288 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -71,41 +71,12 @@ module {{moduleName}} # @return [true, false] attr_accessor :client_side_validation - ### TLS/SSL setting - # Set this to false to skip verifying SSL certificate when calling API from https server. - # Default to true. - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - # @return [true, false] - attr_accessor :verify_ssl - - ### TLS/SSL setting - # Set this to false to skip verifying SSL host name - # Default to true. - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - # @return [true, false] - attr_accessor :verify_ssl_host - - ### TLS/SSL setting - # Set this to customize the certificate file to verify the peer. - # - # @return [String] the path to the certificate file - # - # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: - # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 - attr_accessor :ssl_ca_cert - - ### TLS/SSL setting - # Client certificate file (for client certificate) - attr_accessor :cert_file - - ### TLS/SSL setting - # Client private key file (for client certificate) - attr_accessor :key_file - +{{^isFaraday}} +{{> configuration_tls_typhoeus_partial}} +{{/isFaraday}} +{{#isFaraday}} +{{> configuration_tls_faraday_partial}} +{{/isFaraday}} # Set this to customize parameters encoding of array parameter with multi collectionFormat. # Default to nil. # @@ -125,11 +96,20 @@ module {{moduleName}} @api_key_prefix = {} @timeout = 0 @client_side_validation = true + {{#isFaraday}} + @ssl_verify = true + @ssl_verify_mode = nil + @ssl_ca_file = nil + @ssl_client_cert = nil + @ssl_client_key = nil + {{/isFaraday}} + {{^isFaraday}} @verify_ssl = true @verify_ssl_host = true @params_encoding = nil @cert_file = nil @key_file = nil + {{/isFaraday}} @debugging = false @inject_format = false @force_ending_format = false diff --git a/configuration_tls_faraday_partial.mustache b/configuration_tls_faraday_partial.mustache new file mode 100644 index 000000000000..e5f4085cda24 --- /dev/null +++ b/configuration_tls_faraday_partial.mustache @@ -0,0 +1,29 @@ + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :ssl_verify + + ### TLS/SSL setting + # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html) + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + attr_accessor :ssl_verify_mode + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + attr_accessor :ssl_ca_file + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :ssl_client_cert + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :ssl_client_key diff --git a/configuration_tls_typhoeus_partial.mustache b/configuration_tls_typhoeus_partial.mustache new file mode 100644 index 000000000000..b75954c254a9 --- /dev/null +++ b/configuration_tls_typhoeus_partial.mustache @@ -0,0 +1,34 @@ + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl + + ### TLS/SSL setting + # Set this to false to skip verifying SSL host name + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl_host + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + # + # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: + # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 + attr_accessor :ssl_ca_cert + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :cert_file + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :key_file diff --git a/faraday_api_client.mustache b/faraday_api_client.mustache index f628ffecf070..14509b18a002 100644 --- a/faraday_api_client.mustache +++ b/faraday_api_client.mustache @@ -107,8 +107,6 @@ module {{moduleName}} update_params_for_auth! header_params, query_params, opts[:auth_names] - - req_opts = { :method => http_method, :headers => header_params, @@ -118,7 +116,6 @@ module {{moduleName}} :verbose => @config.debugging } - if [:post, :patch, :put, :delete].include?(http_method) req_body = build_request_body(header_params, form_params, opts[:body]) req_opts.update :body => req_body From 649b6218717f23e123f27b1ba724ee3ff8d18d4a Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 3 Aug 2019 16:36:22 +0800 Subject: [PATCH 38/86] [Ruby] remove auto-generated Gemfile.lock (#3541) * remove auto-generated gemlock file * update test file to conform to rubocop format --- Gemfile.lock.mustache | 79 ------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 Gemfile.lock.mustache diff --git a/Gemfile.lock.mustache b/Gemfile.lock.mustache deleted file mode 100644 index bf18a06ea838..000000000000 --- a/Gemfile.lock.mustache +++ /dev/null @@ -1,79 +0,0 @@ -PATH - remote: . - specs: - {{gemName}}{{^gemName}}{{{appName}}}{{/gemName}} ({{gemVersion}}) - json (~> 2.1, >= 2.1.0) - typhoeus (~> 1.0, >= 1.0.1) - -GEM - remote: https://rubygems.org/ - specs: - ZenTest (4.11.2) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - autotest (4.4.6) - ZenTest (>= 4.4.1) - autotest-fsevent (0.2.14) - sys-uname - autotest-growl (0.2.16) - autotest-rails-pure (4.1.2) - byebug (10.0.2) - coderay (1.1.2) - crack (0.4.3) - safe_yaml (~> 1.0.0) - diff-lcs (1.3) - ethon (0.11.0) - ffi (>= 1.3.0) - ffi (1.9.25) - hashdiff (0.3.7) - json (2.1.0) - method_source (0.9.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.6.0) - byebug (~> 10.0) - pry (~> 0.10) - public_suffix (3.0.3) - rake (12.0.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - safe_yaml (1.0.4) - sys-uname (1.0.3) - ffi (>= 1.0.0) - typhoeus (1.3.0) - ethon (>= 0.9.0) - vcr (3.0.3) - webmock (1.24.6) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff - -PLATFORMS - ruby - -DEPENDENCIES - autotest (~> 4.4, >= 4.4.6) - autotest-fsevent (~> 0.2, >= 0.2.12) - autotest-growl (~> 0.2, >= 0.2.16) - autotest-rails-pure (~> 4.1, >= 4.1.2) - {{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}! - pry-byebug - rake (~> 12.0.0) - rspec (~> 3.6, >= 3.6.0) - vcr (~> 3.0, >= 3.0.1) - webmock (~> 1.24, >= 1.24.3) - -BUNDLED WITH - 1.16.1 From 95b0efc090b8c02d0b974e5bad641daf2b204f1b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 6 Aug 2019 08:52:48 +0800 Subject: [PATCH 39/86] [Ruby] clean up Ruby dev dependencies (#3551) * clean up ruby dev dependencies * update ensure uptodate to cover ruby faraday --- gemspec.mustache | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gemspec.mustache b/gemspec.mustache index e4a486855c5d..0fe63c2e47bc 100644 --- a/gemspec.mustache +++ b/gemspec.mustache @@ -33,12 +33,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0' s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' - s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' - s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' - s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6' - s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2' - s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16' - s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12' s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } s.test_files = `find spec/*`.split("\n") From d9fcd7b389a0193e5f4b686dc119ecdc76dacbcb Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 8 Aug 2019 09:49:01 +0800 Subject: [PATCH 40/86] using partials in ruby api_client (#3564) --- api_client.mustache | 127 +-------- api_client_faraday_partial.mustache | 129 +++++++++ api_client_typhoeus_partial.mustache | 115 ++++++++ faraday_api_client.mustache | 394 --------------------------- 4 files changed, 255 insertions(+), 510 deletions(-) create mode 100644 api_client_faraday_partial.mustache create mode 100644 api_client_typhoeus_partial.mustache delete mode 100644 faraday_api_client.mustache diff --git a/api_client.mustache b/api_client.mustache index 28c762416206..5d263ece7e34 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -6,7 +6,12 @@ require 'date' require 'json' require 'logger' require 'tempfile' +{{^isFaraday}} require 'typhoeus' +{{/isFaraday}} +{{#isFaraday}} +require 'faraday' +{{/isFaraday}} module {{moduleName}} class ApiClient @@ -33,94 +38,12 @@ module {{moduleName}} @@default ||= ApiClient.new end - # Call an API with given options. - # - # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: - # the data deserialized from response body (could be nil), response status code and response headers. - def call_api(http_method, path, opts = {}) - request = build_request(http_method, path, opts) - response = request.run - - if @config.debugging - @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" - end - - unless response.success? - if response.timed_out? - fail ApiError.new('Connection timed out') - elsif response.code == 0 - # Errors from libcurl will be made visible here - fail ApiError.new(:code => 0, - :message => response.return_message) - else - fail ApiError.new(:code => response.code, - :response_headers => response.headers, - :response_body => response.body), - response.status_message - end - end - - if opts[:return_type] - data = deserialize(response, opts[:return_type]) - else - data = nil - end - return data, response.code, response.headers - end - - # Builds the HTTP request - # - # @param [String] http_method HTTP method/verb (e.g. POST) - # @param [String] path URL path (e.g. /account/new) - # @option opts [Hash] :header_params Header parameters - # @option opts [Hash] :query_params Query parameters - # @option opts [Hash] :form_params Query parameters - # @option opts [Object] :body HTTP body (JSON/XML) - # @return [Typhoeus::Request] A Typhoeus Request - def build_request(http_method, path, opts = {}) - url = build_request_url(path) - http_method = http_method.to_sym.downcase - - header_params = @default_headers.merge(opts[:header_params] || {}) - query_params = opts[:query_params] || {} - form_params = opts[:form_params] || {} - - {{#hasAuthMethods}} - update_params_for_auth! header_params, query_params, opts[:auth_names] - {{/hasAuthMethods}} - - # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) - _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 - - req_opts = { - :method => http_method, - :headers => header_params, - :params => query_params, - :params_encoding => @config.params_encoding, - :timeout => @config.timeout, - :ssl_verifypeer => @config.verify_ssl, - :ssl_verifyhost => _verify_ssl_host, - :sslcert => @config.cert_file, - :sslkey => @config.key_file, - :verbose => @config.debugging - } - - # set custom cert, if provided - req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert - - if [:post, :patch, :put, :delete].include?(http_method) - req_body = build_request_body(header_params, form_params, opts[:body]) - req_opts.update :body => req_body - if @config.debugging - @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" - end - end - - request = Typhoeus::Request.new(url, req_opts) - download_file(request) if opts[:return_type] == 'File' - request - end - +{{^isFaraday}} +{{> api_client_typhoeus_partial}} +{{/isFaraday}} +{{#isFaraday}} +{{> api_client_faraday_partial}} +{{/isFaraday}} # Check if the given MIME is a JSON MIME. # JSON MIME examples: # application/json @@ -258,34 +181,6 @@ module {{moduleName}} @config.base_url + path end - # Builds the HTTP request body - # - # @param [Hash] header_params Header parameters - # @param [Hash] form_params Query parameters - # @param [Object] body HTTP body (JSON/XML) - # @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' - data = {} - form_params.each do |key, value| - case value - when ::File, ::Array, nil - # let typhoeus handle File, Array and nil parameters - data[key] = value - else - data[key] = value.to_s - end - end - elsif body - data = body.is_a?(String) ? body : body.to_json - else - data = nil - end - data - end - # Update hearder and query params based on authentication settings. # # @param [Hash] header_params Header parameters diff --git a/api_client_faraday_partial.mustache b/api_client_faraday_partial.mustache new file mode 100644 index 000000000000..7fc08ee0fce1 --- /dev/null +++ b/api_client_faraday_partial.mustache @@ -0,0 +1,129 @@ + # Call an API with given options. + # + # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. + def call_api(http_method, path, opts = {}) + ssl_options = { + :ca_file => @config.ssl_ca_file, + :verify => @config.ssl_verify, + :verify => @config.ssl_verify_mode, + :client_cert => @config.ssl_client_cert, + :client_key => @config.ssl_client_key + } + + connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) 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 + 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 + + 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 + end + rescue Faraday::TimeoutError + fail ApiError.new('Connection timed out') + end + + if opts[:return_type] + data = deserialize(response, opts[:return_type]) + else + data = nil + end + return data, response.status, response.headers + end + + # Builds the HTTP request + # + # @param [String] http_method HTTP method/verb (e.g. POST) + # @param [String] path URL path (e.g. /account/new) + # @option opts [Hash] :header_params Header parameters + # @option opts [Hash] :query_params Query parameters + # @option opts [Hash] :form_params Query parameters + # @option opts [Object] :body HTTP body (JSON/XML) + # @return [Typhoeus::Request] A Typhoeus Request + def build_request(http_method, path, request, opts = {}) + url = build_request_url(path) + http_method = http_method.to_sym.downcase + + header_params = @default_headers.merge(opts[:header_params] || {}) + query_params = opts[:query_params] || {} + form_params = opts[:form_params] || {} + + update_params_for_auth! header_params, query_params, opts[:auth_names] + + req_opts = { + :method => http_method, + :headers => header_params, + :params => query_params, + :params_encoding => @config.params_encoding, + :timeout => @config.timeout, + :verbose => @config.debugging + } + + if [:post, :patch, :put, :delete].include?(http_method) + req_body = build_request_body(header_params, form_params, opts[:body]) + req_opts.update :body => req_body + if @config.debugging + @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" + end + end + request.headers = header_params + request.body = req_body + request.url url + request.params = query_params + download_file(request) if opts[:return_type] == 'File' + request + end + + # Builds the HTTP request body + # + # @param [Hash] header_params Header parameters + # @param [Hash] form_params Query parameters + # @param [Object] body HTTP body (JSON/XML) + # @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' + 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 + # 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 + else + data[key] = value.to_s + end + end + elsif body + data = body.is_a?(String) ? body : body.to_json + else + data = nil + end + data + end diff --git a/api_client_typhoeus_partial.mustache b/api_client_typhoeus_partial.mustache new file mode 100644 index 000000000000..bd554afc0066 --- /dev/null +++ b/api_client_typhoeus_partial.mustache @@ -0,0 +1,115 @@ + # Call an API with given options. + # + # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. + def call_api(http_method, path, opts = {}) + request = build_request(http_method, path, opts) + response = request.run + + if @config.debugging + @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" + end + + unless response.success? + if response.timed_out? + fail ApiError.new('Connection timed out') + elsif response.code == 0 + # Errors from libcurl will be made visible here + fail ApiError.new(:code => 0, + :message => response.return_message) + else + fail ApiError.new(:code => response.code, + :response_headers => response.headers, + :response_body => response.body), + response.status_message + end + end + + if opts[:return_type] + data = deserialize(response, opts[:return_type]) + else + data = nil + end + return data, response.code, response.headers + end + + # Builds the HTTP request + # + # @param [String] http_method HTTP method/verb (e.g. POST) + # @param [String] path URL path (e.g. /account/new) + # @option opts [Hash] :header_params Header parameters + # @option opts [Hash] :query_params Query parameters + # @option opts [Hash] :form_params Query parameters + # @option opts [Object] :body HTTP body (JSON/XML) + # @return [Typhoeus::Request] A Typhoeus Request + def build_request(http_method, path, opts = {}) + url = build_request_url(path) + http_method = http_method.to_sym.downcase + + header_params = @default_headers.merge(opts[:header_params] || {}) + query_params = opts[:query_params] || {} + form_params = opts[:form_params] || {} + + {{#hasAuthMethods}} + update_params_for_auth! header_params, query_params, opts[:auth_names] + {{/hasAuthMethods}} + + # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) + _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 + + req_opts = { + :method => http_method, + :headers => header_params, + :params => query_params, + :params_encoding => @config.params_encoding, + :timeout => @config.timeout, + :ssl_verifypeer => @config.verify_ssl, + :ssl_verifyhost => _verify_ssl_host, + :sslcert => @config.cert_file, + :sslkey => @config.key_file, + :verbose => @config.debugging + } + + # set custom cert, if provided + req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert + + if [:post, :patch, :put, :delete].include?(http_method) + req_body = build_request_body(header_params, form_params, opts[:body]) + req_opts.update :body => req_body + if @config.debugging + @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" + end + end + + request = Typhoeus::Request.new(url, req_opts) + download_file(request) if opts[:return_type] == 'File' + request + end + + # Builds the HTTP request body + # + # @param [Hash] header_params Header parameters + # @param [Hash] form_params Query parameters + # @param [Object] body HTTP body (JSON/XML) + # @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' + data = {} + form_params.each do |key, value| + case value + when ::File, ::Array, nil + # let typhoeus handle File, Array and nil parameters + data[key] = value + else + data[key] = value.to_s + end + end + elsif body + data = body.is_a?(String) ? body : body.to_json + else + data = nil + end + data + end diff --git a/faraday_api_client.mustache b/faraday_api_client.mustache deleted file mode 100644 index 14509b18a002..000000000000 --- a/faraday_api_client.mustache +++ /dev/null @@ -1,394 +0,0 @@ -=begin -{{> api_info}} -=end - -require 'date' -require 'faraday' -require 'json' -require 'logger' -require 'tempfile' - -module {{moduleName}} - class ApiClient - # The Configuration object holding settings to be used in the API client. - attr_accessor :config - - # Defines the headers to be used in HTTP requests of all API calls by default. - # - # @return [Hash] - attr_accessor :default_headers - - # Initializes the ApiClient - # @option config [Configuration] Configuration for initializing the object, default to Configuration.default - def initialize(config = Configuration.default) - @config = config - @user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/#{VERSION}/ruby{{/httpUserAgent}}" - @default_headers = { - 'Content-Type' => 'application/json', - 'User-Agent' => @user_agent - } - end - - def self.default - @@default ||= ApiClient.new - end - - # Call an API with given options. - # - # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: - # the data deserialized from response body (could be nil), response status code and response headers. - def call_api(http_method, path, opts = {}) - ssl_options = { - :ca_file => @config.ssl_ca_file, - :verify => @config.ssl_verify, - :verify => @config.ssl_verify_mode, - :client_cert => @config.ssl_client_cert, - :client_key => @config.ssl_client_key - } - - connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) 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 - 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 - - 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 - end - rescue Faraday::TimeoutError - fail ApiError.new('Connection timed out') - end - - if opts[:return_type] - data = deserialize(response, opts[:return_type]) - else - data = nil - end - return data, response.status, response.headers - end - - # Builds the HTTP request - # - # @param [String] http_method HTTP method/verb (e.g. POST) - # @param [String] path URL path (e.g. /account/new) - # @option opts [Hash] :header_params Header parameters - # @option opts [Hash] :query_params Query parameters - # @option opts [Hash] :form_params Query parameters - # @option opts [Object] :body HTTP body (JSON/XML) - # @return [Typhoeus::Request] A Typhoeus Request - def build_request(http_method, path, request, opts = {}) - url = build_request_url(path) - http_method = http_method.to_sym.downcase - - header_params = @default_headers.merge(opts[:header_params] || {}) - query_params = opts[:query_params] || {} - form_params = opts[:form_params] || {} - - update_params_for_auth! header_params, query_params, opts[:auth_names] - - req_opts = { - :method => http_method, - :headers => header_params, - :params => query_params, - :params_encoding => @config.params_encoding, - :timeout => @config.timeout, - :verbose => @config.debugging - } - - if [:post, :patch, :put, :delete].include?(http_method) - req_body = build_request_body(header_params, form_params, opts[:body]) - req_opts.update :body => req_body - if @config.debugging - @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" - end - end - request.headers = header_params - request.body = req_body - request.url url - request.params = query_params - download_file(request) if opts[:return_type] == 'File' - request - end - - # Check if the given MIME is a JSON MIME. - # JSON MIME examples: - # application/json - # application/json; charset=UTF8 - # APPLICATION/JSON - # */* - # @param [String] mime MIME - # @return [Boolean] True if the MIME is application/json - def json_mime?(mime) - (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil? - end - - # Deserialize the response to the given return type. - # - # @param [Response] response HTTP response - # @param [String] return_type some examples: "User", "Array", "Hash" - def deserialize(response, return_type) - body = response.body - - # handle file downloading - return the File instance processed in request callbacks - # note that response body is empty when the file is written in chunks in request on_body callback - return @tempfile if return_type == 'File' - - return nil if body.nil? || body.empty? - - # return response body directly for String return type - return body if return_type == 'String' - - # ensuring a default content type - content_type = response.headers['Content-Type'] || 'application/json' - - fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) - - begin - data = JSON.parse("[#{body}]", :symbolize_names => true)[0] - rescue JSON::ParserError => e - if %w(String Date DateTime).include?(return_type) - data = body - else - raise e - end - end - - convert_to_type data, return_type - end - - # Convert data to the given return type. - # @param [Object] data Data to be converted - # @param [String] return_type Return type - # @return [Mixed] Data in a particular type - def convert_to_type(data, return_type) - return nil if data.nil? - case return_type - when 'String' - data.to_s - when 'Integer' - data.to_i - when 'Float' - data.to_f - when 'Boolean' - data == true - when 'DateTime' - # parse date time (expecting ISO 8601 format) - DateTime.parse data - when 'Date' - # parse date time (expecting ISO 8601 format) - Date.parse data - when 'Object' - # generic object (usually a Hash), return directly - data - when /\AArray<(.+)>\z/ - # e.g. Array - sub_type = $1 - data.map { |item| convert_to_type(item, sub_type) } - when /\AHash\\z/ - # e.g. Hash - sub_type = $1 - {}.tap do |hash| - data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } - end - else - # models, e.g. Pet - {{moduleName}}.const_get(return_type).build_from_hash(data) - end - end - - # Save response body into a file in (the defined) temporary folder, using the filename - # from the "Content-Disposition" header if provided, otherwise a random filename. - # The response body is written to the file in chunks in order to handle files which - # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby - # process can use. - # - # @see Configuration#temp_folder_path - def download_file(request) - tempfile = nil - encoding = nil - request.on_headers do |response| - content_disposition = response.headers['Content-Disposition'] - if content_disposition && content_disposition =~ /filename=/i - filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] - prefix = sanitize_filename(filename) - else - prefix = 'download-' - end - prefix = prefix + '-' unless prefix.end_with?('-') - encoding = response.body.encoding - tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) - @tempfile = tempfile - end - request.on_body do |chunk| - chunk.force_encoding(encoding) - tempfile.write(chunk) - end - request.on_complete do |response| - tempfile.close if tempfile - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" - end - end - - # Sanitize filename by removing path. - # e.g. ../../sun.gif becomes sun.gif - # - # @param [String] filename the filename to be sanitized - # @return [String] the sanitized filename - def sanitize_filename(filename) - filename.gsub(/.*[\/\\]/, '') - end - - def build_request_url(path) - # Add leading and trailing slashes to path - path = "/#{path}".gsub(/\/+/, '/') - @config.base_url + path - end - - # Builds the HTTP request body - # - # @param [Hash] header_params Header parameters - # @param [Hash] form_params Query parameters - # @param [Object] body HTTP body (JSON/XML) - # @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' - 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 - # 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 - else - data[key] = value.to_s - end - end - elsif body - data = body.is_a?(String) ? body : body.to_json - else - data = nil - end - data - end - - # Update hearder and query params based on authentication settings. - # - # @param [Hash] header_params Header parameters - # @param [Hash] query_params Query parameters - # @param [String] auth_names Authentication scheme name - def update_params_for_auth!(header_params, query_params, auth_names) - Array(auth_names).each do |auth_name| - auth_setting = @config.auth_settings[auth_name] - next unless auth_setting - case auth_setting[:in] - when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] - when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] - else fail ArgumentError, 'Authentication token must be in `query` of `header`' - end - end - end - - # Sets user agent in HTTP header - # - # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) - def user_agent=(user_agent) - @user_agent = user_agent - @default_headers['User-Agent'] = @user_agent - end - - # Return Accept header based on an array of accepts provided. - # @param [Array] accepts array for Accept - # @return [String] the Accept header (e.g. application/json) - def select_header_accept(accepts) - return nil if accepts.nil? || accepts.empty? - # use JSON when present, otherwise use all of the provided - json_accept = accepts.find { |s| json_mime?(s) } - json_accept || accepts.join(',') - end - - # Return Content-Type header based on an array of content types provided. - # @param [Array] content_types array for Content-Type - # @return [String] the Content-Type header (e.g. application/json) - def select_header_content_type(content_types) - # use application/json by default - return 'application/json' if content_types.nil? || content_types.empty? - # use JSON when present, otherwise use the first one - json_content_type = content_types.find { |s| json_mime?(s) } - json_content_type || content_types.first - end - - # Convert object (array, hash, object, etc) to JSON string. - # @param [Object] model object to be converted into JSON string - # @return [String] JSON string representation of the object - def object_to_http_body(model) - return model if model.nil? || model.is_a?(String) - local_body = nil - if model.is_a?(Array) - local_body = model.map { |m| object_to_hash(m) } - else - local_body = object_to_hash(model) - end - local_body.to_json - end - - # Convert object(non-array) to hash. - # @param [Object] obj object to be converted into JSON string - # @return [String] JSON string representation of the object - def object_to_hash(obj) - if obj.respond_to?(:to_hash) - obj.to_hash - else - obj - end - end - - # Build parameter value according to the given collection format. - # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi - def build_collection_param(param, collection_format) - case collection_format - when :csv - param.join(',') - when :ssv - param.join(' ') - when :tsv - param.join("\t") - when :pipes - param.join('|') - when :multi - # return the array directly as typhoeus will handle it as expected - param - else - fail "unknown collection format: #{collection_format.inspect}" - end - end - end -end From 6b4965a48aeaa47aee6fd1db4fc38456c2b0504a Mon Sep 17 00:00:00 2001 From: Justin Sherrill Date: Thu, 15 Aug 2019 20:45:18 -0400 Subject: [PATCH 41/86] [Ruby][faraday] Properly pass verify_mode to faraday (#3652) --- api_client_faraday_partial.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_client_faraday_partial.mustache b/api_client_faraday_partial.mustache index 7fc08ee0fce1..fec52da71b2f 100644 --- a/api_client_faraday_partial.mustache +++ b/api_client_faraday_partial.mustache @@ -6,7 +6,7 @@ ssl_options = { :ca_file => @config.ssl_ca_file, :verify => @config.ssl_verify, - :verify => @config.ssl_verify_mode, + :verify_mode => @config.ssl_verify_mode, :client_cert => @config.ssl_client_cert, :client_key => @config.ssl_client_key } From eaaff70e424f1b5c46643180f525f0c22f0655e0 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Mon, 19 Aug 2019 14:31:34 +0900 Subject: [PATCH 42/86] fix the model's `valid?` of Ruby client to prevent runtime error (#3670) (#3671) --- partial_model_generic.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 65351bad6e5c..f0d7c40a5bce 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -246,14 +246,14 @@ {{#anyOf}} {{#-first}} _any_of_found = false - openapi_any_of.each do |_class| + self.class.openapi_any_of.each do |_class| _any_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash) if _any_of.valid? _any_of_found = true end end - if !_any_of_found? + if !_any_of_found return false end @@ -262,10 +262,10 @@ {{#oneOf}} {{#-first}} _one_of_found = false - openapi_one_of.each do |_class| + self.class.openapi_one_of.each do |_class| _one_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash) if _one_of.valid? - if _one_of_found? + if _one_of_found return false else _one_of_found = true @@ -273,7 +273,7 @@ end end - if !_one_of_found? + if !_one_of_found return false end From 2d043db19e5024bf6ca29d2d062409fd9d718bb7 Mon Sep 17 00:00:00 2001 From: Quim Muntal Date: Tue, 3 Sep 2019 15:35:49 +0200 Subject: [PATCH 43/86] Support custom git repository (#3757) * add gitHost param to GeneratorSettings and related * parameterize gitHost in READMEs * parameterize gitHost in go.mod * parameterize gitHost in git_push * update petstore samples * run ./bin/utils/export_docs_generators.sh * run meta-codehen.sh * Revert "run meta-codehen.sh" This reverts commit d6d579f6159186531257cdfdd73b9caf9e9ffeba. * Revert "run ./bin/utils/export_docs_generators.sh" This reverts commit 1b81538198d4319fd1b4e97447303e3cc0e8dc99. * Revert "update petstore samples" This reverts commit f513add88396707f6991ae2e4920359583ec88f1. * run ensure-up-to-date --- README.mustache | 4 ++-- git_push.sh.mustache | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.mustache b/README.mustache index 182bb34f4f50..5303a2f7797f 100644 --- a/README.mustache +++ b/README.mustache @@ -44,9 +44,9 @@ Finally add this to the Gemfile: ### Install from Git -If the Ruby gem is hosted at a git repository: https://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile: +If the Ruby gem is hosted at a git repository: https://{{gitHost}}/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile: - gem '{{{gemName}}}', :git => 'https://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git' + gem '{{{gemName}}}', :git => 'https://{{gitHost}}/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git' ### Include the Ruby code directly diff --git a/git_push.sh.mustache b/git_push.sh.mustache index 5807579d6eff..8b3f689c9121 100755 --- a/git_push.sh.mustache +++ b/git_push.sh.mustache @@ -1,14 +1,17 @@ #!/bin/sh -# -# Generated by: https://openapi-generator.tech -# # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" git_user_id=$1 git_repo_id=$2 release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="{{{gitHost}}}" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi if [ "$git_user_id" = "" ]; then git_user_id="{{{gitUserId}}}" @@ -40,9 +43,9 @@ if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git fi fi @@ -50,6 +53,6 @@ fi git pull origin master # Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" git push origin master 2>&1 | grep -v 'To https' From b62bbe122619cd321d435815def2ecd518924754 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 4 Oct 2019 01:42:28 +0800 Subject: [PATCH 44/86] [Ruby] fix ruby test, update error message (#4041) * fix ruby test, update error message * use block * update template for api client spec * update test files --- api_client_spec.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_client_spec.mustache b/api_client_spec.mustache index 3e8d070ef9f7..364c60419c4f 100644 --- a/api_client_spec.mustache +++ b/api_client_spec.mustache @@ -150,7 +150,7 @@ describe {{moduleName}}::ApiClient do end it 'fails for invalid collection format' do - expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID') + expect{api_client.build_collection_param(param, :INVALID)}.to raise_error(RuntimeError, 'unknown collection format: :INVALID') end end From fbe5404ed7ece46c2239cb3debb36bdc5e310589 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 9 Oct 2019 15:16:22 +0800 Subject: [PATCH 45/86] Fix readonly with isReadOnly (#4102) * fix readonly * update samples --- model_doc.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model_doc.mustache b/model_doc.mustache index 2112d2bc6d71..c2a790d9dace 100644 --- a/model_doc.mustache +++ b/model_doc.mustache @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} {{/vars}} ## Code Sample From 256f75bcc4f4762e87a49adb93a7234a28b7fede Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Thu, 7 Nov 2019 09:15:00 +0100 Subject: [PATCH 46/86] Ruby client nullable (#4391) * Ruby Client: implementation of nullable * Ruby samples with nullable implementation * [Ruby] openapi_nullable as a Set and skipping attrs fix --- base_object.mustache | 6 +++++- partial_model_generic.mustache | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/base_object.mustache b/base_object.mustache index 0a663ef944aa..cf4a62a99eb2 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -87,7 +87,11 @@ hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) - next if value.nil? + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + hash[param] = _to_hash(value) end hash diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index f0d7c40a5bce..536d8f2926be 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -51,6 +51,17 @@ } end + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + {{#vars}} + {{#isNullable}} + :'{{{name}}}'{{#hasMore}},{{/hasMore}} + {{/isNullable}} + {{/vars}} + ]) + end + {{#anyOf}} {{#-first}} # List of class defined in anyOf (OpenAPI v3) From 2fcfc6fd0cab5c6620859f70fbff1c77cf4e86b7 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Thu, 28 Nov 2019 07:13:46 +0100 Subject: [PATCH 47/86] [Ruby] Fix typo in description (#4624) --- configuration.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configuration.mustache b/configuration.mustache index 72f6fe90e288..3c2f87e37e4a 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -217,13 +217,13 @@ module {{moduleName}} {{#servers}} { url: "{{{url}}}", - description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + description: "{{{description}}}{{^description}}No description provided{{/description}}", {{#variables}} {{#-first}} variables: { {{/-first}} {{{name}}}: { - description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", + description: "{{{description}}}{{^description}}No description provided{{/description}}", default_value: "{{{defaultValue}}}", {{#enumValues}} {{#-first}} From d8587f1b3f19d6d492a677f8a20d1ce666593d12 Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Fri, 29 Nov 2019 10:59:17 +0900 Subject: [PATCH 48/86] delete unused mustache in ruby-client (#4638) --- faraday_configuration.mustache | 300 --------------------------------- 1 file changed, 300 deletions(-) delete mode 100644 faraday_configuration.mustache diff --git a/faraday_configuration.mustache b/faraday_configuration.mustache deleted file mode 100644 index 67aaaf4f00f6..000000000000 --- a/faraday_configuration.mustache +++ /dev/null @@ -1,300 +0,0 @@ -=begin -{{> api_info}} -=end - -module {{moduleName}} - class Configuration - # Defines url scheme - attr_accessor :scheme - - # Defines url host - attr_accessor :host - - # Defines url base path - attr_accessor :base_path - - # Defines API keys used with API Key authentications. - # - # @return [Hash] key: parameter name, value: parameter value (API key) - # - # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string) - # config.api_key['api_key'] = 'xxx' - attr_accessor :api_key - - # Defines API key prefixes used with API Key authentications. - # - # @return [Hash] key: parameter name, value: API key prefix - # - # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers) - # config.api_key_prefix['api_key'] = 'Token' - attr_accessor :api_key_prefix - - # Defines the username used with HTTP basic authentication. - # - # @return [String] - attr_accessor :username - - # Defines the password used with HTTP basic authentication. - # - # @return [String] - attr_accessor :password - - # Defines the access token (Bearer) used with OAuth2. - attr_accessor :access_token - - # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response - # details will be logged with `logger.debug` (see the `logger` attribute). - # Default to false. - # - # @return [true, false] - attr_accessor :debugging - - # Defines the logger used for debugging. - # Default to `Rails.logger` (when in Rails) or logging to STDOUT. - # - # @return [#debug] - attr_accessor :logger - - # Defines the temporary folder to store downloaded files - # (for API endpoints that have file response). - # Default to use `Tempfile`. - # - # @return [String] - attr_accessor :temp_folder_path - - # The time limit for HTTP request in seconds. - # Default to 0 (never times out). - attr_accessor :timeout - - # Set this to false to skip client side validation in the operation. - # Default to true. - # @return [true, false] - attr_accessor :client_side_validation - - # Set this to false to skip client side validation in the operation. - # Default to true. - # @return [true, false] - attr_accessor :client_side_validation - - ### TLS/SSL setting - # Set this to false to skip verifying SSL certificate when calling API from https server. - # Default to true. - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - # @return [true, false] - attr_accessor :ssl_verify - - ### TLS/SSL setting - # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html) - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - attr_accessor :ssl_verify_mode - - ### TLS/SSL setting - # Set this to customize the certificate file to verify the peer. - # - # @return [String] the path to the certificate file - attr_accessor :ssl_ca_file - - ### TLS/SSL setting - # Client certificate file (for client certificate) - attr_accessor :ssl_client_cert - - ### TLS/SSL setting - # Client private key file (for client certificate) - attr_accessor :ssl_client_key - - # Set this to customize parameters encoding of array parameter with multi collectionFormat. - # Default to nil. - # - # @see The params_encoding option of Ethon. Related source code: - # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 - attr_accessor :params_encoding - - attr_accessor :inject_format - - attr_accessor :force_ending_format - - def initialize - @scheme = 'http' - @host = 'localhost' - @base_path = '' - @api_key = {} - @api_key_prefix = {} - @params_encoding = nil - @timeout = 0 - @client_side_validation = true - @ssl_verify = true - @ssl_verify_mode = nil - @ssl_ca_file = nil - @ssl_client_cert = nil - @ssl_client_key = nil - @debugging = false - @inject_format = false - @force_ending_format = false - @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) - - yield(self) if block_given? - end - - # The default Configuration object. - def self.default - @@default ||= Configuration.new - end - - def configure - yield(self) if block_given? - end - - def scheme=(scheme) - # remove :// from scheme - @scheme = scheme.sub(/:\/\//, '') - end - - def host=(host) - # remove http(s):// and anything after a slash - @host = host.sub(/https?:\/\//, '').split('/').first - end - - def base_path=(base_path) - # Add leading and trailing slashes to base_path - @base_path = "/#{base_path}".gsub(/\/+/, '/') - @base_path = '' if @base_path == '/' - end - - def base_url - "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') - end - - # Gets API key (with prefix if set). - # @param [String] param_name the parameter name of API key auth - def api_key_with_prefix(param_name) - if @api_key_prefix[param_name] - "#{@api_key_prefix[param_name]} #{@api_key[param_name]}" - else - @api_key[param_name] - end - end - - # Gets Basic Auth token string - def basic_auth_token - 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") - end - - # Returns Auth Settings hash for api client. - def auth_settings - { -{{#authMethods}} -{{#isApiKey}} - '{{name}}' => - { - type: 'api_key', - in: {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}, - key: '{{keyParamName}}', - value: api_key_with_prefix('{{keyParamName}}') - }, -{{/isApiKey}} -{{#isBasic}} -{{^isBasicBearer}} - '{{name}}' => - { - type: 'basic', - in: 'header', - key: 'Authorization', - value: basic_auth_token - }, -{{/isBasicBearer}} -{{#isBasicBearer}} - '{{name}}' => - { - type: 'bearer', - in: 'header', - {{#bearerFormat}} - format: '{{{.}}}', - {{/bearerFormat}} - key: 'Authorization', - value: "Bearer #{access_token}" - }, -{{/isBasicBearer}} -{{/isBasic}} -{{#isOAuth}} - '{{name}}' => - { - type: 'oauth2', - in: 'header', - key: 'Authorization', - value: "Bearer #{access_token}" - }, -{{/isOAuth}} -{{/authMethods}} - } - end - - # Returns an array of Server setting - def server_settings - [ - {{#servers}} - { - url: "{{{url}}}", - description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", - {{#variables}} - {{#-first}} - variables: { - {{/-first}} - {{{name}}}: { - description: "{{{description}}}{{^description}}No descriptoin provided{{/description}}", - default_value: "{{{defaultValue}}}", - {{#enumValues}} - {{#-first}} - enum_values: [ - {{/-first}} - "{{{.}}}"{{^-last}},{{/-last}} - {{#-last}} - ] - {{/-last}} - {{/enumValues}} - }{{^-last}},{{/-last}} - {{#-last}} - } - {{/-last}} - {{/variables}} - }{{^-last}},{{/-last}} - {{/servers}} - ] - end - - # Returns URL based on server settings - # - # @param index array index of the server settings - # @param variables hash of variable and the corresponding value - def server_url(index, variables = {}) - servers = server_settings - - # check array index out of bound - if (index < 0 || index >= servers.size) - fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" - end - - server = servers[index] - url = server[:url] - - # go through variable and assign a value - server[:variables].each do |name, variable| - if variables.key?(name) - if (server[:variables][name][:enum_values].include? variables[name]) - url.gsub! "{" + name.to_s + "}", variables[name] - else - fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." - end - else - # use default value - url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] - end - end - - url - end - end -end From 187dc1bdac1d4bb2f987822c8663b968f6b734a7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 3 Jan 2020 14:59:30 +0800 Subject: [PATCH 49/86] remove base_object_spec.mustache from ruby client (#4918) --- base_object_spec.mustache | 109 -------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 base_object_spec.mustache diff --git a/base_object_spec.mustache b/base_object_spec.mustache deleted file mode 100644 index 56425d65461e..000000000000 --- a/base_object_spec.mustache +++ /dev/null @@ -1,109 +0,0 @@ -require 'spec_helper' - -class ArrayMapObject < Petstore::Category - attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map, :boolean_true_arr, :boolean_false_arr - - def self.attribute_map - { - :int_arr => :int_arr, - :pet_arr => :pet_arr, - :int_map => :int_map, - :pet_map => :pet_map, - :int_arr_map => :int_arr_map, - :pet_arr_map => :pet_arr_map, - :boolean_true_arr => :boolean_true_arr, - :boolean_false_arr => :boolean_false_arr, - } - end - - def self.openapi_types - { - :int_arr => :'Array', - :pet_arr => :'Array', - :int_map => :'Hash', - :pet_map => :'Hash', - :int_arr_map => :'Hash>', - :pet_arr_map => :'Hash>', - :boolean_true_arr => :'Array', - :boolean_false_arr => :'Array', - } - end -end - -describe 'BaseObject' do - describe 'boolean values' do - let(:obj) { Petstore::Cat.new({declawed: false}) } - - it 'should have values set' do - expect(obj.declawed).not_to be_nil - expect(obj.declawed).to eq(false) - end - end - - describe 'array and map properties' do - let(:obj) { ArrayMapObject.new } - - let(:data) do - {int_arr: [123, 456], - pet_arr: [{name: 'Kitty'}], - int_map: {'int' => 123}, - pet_map: {'pet' => {name: 'Kitty'}}, - int_arr_map: {'int_arr' => [123, 456]}, - pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]}, - boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"], - boolean_false_arr: [false, "", 0, "0", "f", nil, "null"], - } - end - - it 'works for #build_from_hash' do - obj.build_from_hash(data) - - expect(obj.int_arr).to match_array([123, 456]) - - expect(obj.pet_arr).to be_instance_of(Array) - expect(obj.pet_arr).to be_instance_of(1) - - pet = obj.pet_arr.first - expect(pet).to be_instance_of(Petstore::Pet) - expect(pet.name).to eq('Kitty') - - expect(obj.int_map).to be_instance_of(Hash) - expect(obj.int_map).to eq({'int' => 123}) - - expect(obj.pet_map).to be_instance_of(Hash) - pet = obj.pet_map['pet'] - expect(pet).to be_instance_of(Petstore::Pet) - expect(pet.name).to eq('Kitty') - - expect(obj.int_arr_map).to be_instance_of(Hash) - arr = obj.int_arr_map['int_arr'] - expect(arr).to match_array([123, 456]) - - expect(obj.pet_arr_map).to be_instance_of(Hash) - arr = obj.pet_arr_map['pet_arr'] - expect(arr).to be_instance_of(Array) - expect(arr.size).to eq(1) - pet = arr.first - expect(pet).to be_instance_of(Petstore::Pet) - expect(pet.name).to eq('Kitty') - - expect(obj.boolean_true_arr).to be_instance_of(Array) - obj.boolean_true_arr.each do |b| - expect(b).to eq(true) - end - - expect(obj.boolean_false_arr).to be_instance_of(Array) - obj.boolean_false_arr.each do |b| - expect(b).to eq(false) - end - end - - it 'works for #to_hash' do - obj.build_from_hash(data) - expect_data = data.dup - expect_data[:boolean_true_arr].map! {true} - expect_data[:boolean_false_arr].map! {false} - expect(obj.to_hash).to eq(expect_data) - end - end -end From 1a2e1f05daf83682367c2549a83a7798eeb07dee Mon Sep 17 00:00:00 2001 From: Sebastien Rosset Date: Thu, 23 Jan 2020 18:35:56 -0800 Subject: [PATCH 50/86] [HttpBasicAuth] Use positive isBasicBasic tag instead of negative isBasicBearer (#5095) * use positive isBasicBasic tag instead of negative isBasicBearer * use positive isBasicBasic tag instead of negative isBasicBearer --- README.mustache | 8 ++++---- api_doc.mustache | 4 ++-- configuration.mustache | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.mustache b/README.mustache index 5303a2f7797f..a527f6ce9d7f 100644 --- a/README.mustache +++ b/README.mustache @@ -65,10 +65,10 @@ Please follow the [installation](#installation) procedure and then run the follo require '{{{gemName}}}' {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}} # Setup authorization -{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}} +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} # Configure HTTP basic authorization: {{{name}}} config.username = 'YOUR_USERNAME' - config.password = 'YOUR_PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}} + config.password = 'YOUR_PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}} # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} @@ -131,8 +131,8 @@ Class | Method | HTTP request | Description - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}} -{{^isBasicBearer}}- **Type**: HTTP basic authentication -{{/isBasicBearer}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} +{{#isBasicBasic}}- **Type**: HTTP basic authentication +{{/isBasicBasic}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} diff --git a/api_doc.mustache b/api_doc.mustache index dc163725e163..0e5d35513e32 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -27,10 +27,10 @@ Method | HTTP request | Description require '{{{gemName}}}' {{#hasAuthMethods}} # setup authorization -{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}} +{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} # Configure HTTP basic authorization: {{{name}}} config.username = 'YOUR USERNAME' - config.password = 'YOUR PASSWORD'{{/isBasicBearer}}{{#isBasicBearer}} + config.password = 'YOUR PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}} # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} diff --git a/configuration.mustache b/configuration.mustache index 3c2f87e37e4a..5e2f57980c4b 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -176,7 +176,7 @@ module {{moduleName}} }, {{/isApiKey}} {{#isBasic}} -{{^isBasicBearer}} +{{#isBasicBasic}} '{{name}}' => { type: 'basic', @@ -184,7 +184,7 @@ module {{moduleName}} key: 'Authorization', value: basic_auth_token }, -{{/isBasicBearer}} +{{/isBasicBasic}} {{#isBasicBearer}} '{{name}}' => { From ad778d63bb3c007245bd247fd24c408de098d90d Mon Sep 17 00:00:00 2001 From: Akira Tanimura Date: Fri, 28 Feb 2020 21:36:25 +0900 Subject: [PATCH 51/86] [Ruby] Fix obsolete configuration of Rubocop and Rubocop's warns (#5417) (#5474) * fix obsolute configuration in generated .rubocop.yml * fix style of `expect` with block in generated ruby client's test code * update sample of ruby client --- api_client_spec.mustache | 2 +- rubocop.mustache | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/api_client_spec.mustache b/api_client_spec.mustache index 364c60419c4f..a079cc9fd350 100644 --- a/api_client_spec.mustache +++ b/api_client_spec.mustache @@ -150,7 +150,7 @@ describe {{moduleName}}::ApiClient do end it 'fails for invalid collection format' do - expect{api_client.build_collection_param(param, :INVALID)}.to raise_error(RuntimeError, 'unknown collection format: :INVALID') + expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID') end end diff --git a/rubocop.mustache b/rubocop.mustache index 0ef33ce5e322..df46058490d0 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -14,12 +14,6 @@ AllCops: Style/AndOr: Enabled: true -# Do not use braces for hash literals when they are the last argument of a -# method call. -Style/BracesAroundHashParameters: - Enabled: true - EnforcedStyle: context_dependent - # Align `when` with `case`. Layout/CaseIndentation: Enabled: true @@ -46,7 +40,7 @@ Layout/EmptyLinesAroundMethodBody: Layout/EmptyLinesAroundModuleBody: Enabled: true -Layout/IndentFirstArgument: +Layout/FirstArgumentIndentation: Enabled: true # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. @@ -57,7 +51,7 @@ Style/HashSyntax: # extra level of indentation. Layout/IndentationConsistency: Enabled: true - EnforcedStyle: rails + EnforcedStyle: indented_internal_methods # Two spaces, no tabs (for indentation). Layout/IndentationWidth: @@ -123,7 +117,7 @@ Layout/Tab: Enabled: true # Blank lines should not have any spaces. -Layout/TrailingBlankLines: +Layout/TrailingEmptyLines: Enabled: true # No trailing whitespace. @@ -131,7 +125,7 @@ Layout/TrailingWhitespace: Enabled: false # Use quotes for string literals when they are enough. -Style/UnneededPercentQ: +Style/RedundantPercentQ: Enabled: true # Align `end` with the matching keyword or starting expression except for From 260811ce48c5c5d613842d83a4c1024ee8647d3f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 29 Feb 2020 19:04:34 +0800 Subject: [PATCH 52/86] fix CVE-2020-8130 (#5483) --- Gemfile.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.mustache b/Gemfile.mustache index 69255e559f7c..c2e3127cdcfe 100644 --- a/Gemfile.mustache +++ b/Gemfile.mustache @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem 'rake', '~> 12.0.0' + gem 'rake', '~> 13.0.1' gem 'pry-byebug' gem 'rubocop', '~> 0.66.0' end From 700bee96e3db5c504e96cd6a6799fa17e7f1af47 Mon Sep 17 00:00:00 2001 From: Timur Platonov Date: Tue, 31 Mar 2020 19:10:31 +0300 Subject: [PATCH 53/86] fix request.on_complete message when tempfile is nil (#5745) * fix request.on_complete message when tempfile is nil * update faraday client sample * add openapi3 client samples --- api_client.mustache | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index 5d263ece7e34..f3139eaa46eb 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -158,11 +158,13 @@ module {{moduleName}} tempfile.write(chunk) end request.on_complete do |response| - tempfile.close if tempfile - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" + if tempfile + tempfile.close + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + end end end From bcf0450ced9721548025e5f6ff415e9ce84a8832 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 22 Apr 2020 11:47:08 +0800 Subject: [PATCH 54/86] Sync master to 5.0.x (#5968) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change the Model template (#5222) * Add a link to Xero blog post (#5426) * Removal of Encoding in the Query-Params in order to prevent double Encoding. (#5255) This way letting WebClient do its Job in encoding the URL. * update java webclient sample * [kotlin][client] Add Jackson as serialization library (#5236) * [kotlin][client] Add Jackson as serialization library * [kotlin][client] Add kotlin-client-jackson.sh to kotlin-client-all.sh * update kotlin client samples * update doc Co-authored-by: William Cheng * include kotlin jackson in CI tests (#5438) * [Ruby] Add error output (#5428) * Add error output to the log so that we can make sure why the error occurred * Fix forbidden method invocation using default charsets * Update usage.md (#5443) * fix NPE for enum (#5445) * [Java][WebClient] better code format (#5433) * better code format for java webclient * prefix local varaible with localVar * fix issue with online service (#5461) * Support for additionalProperties in the C generator "Client: C" solves #5395 (#5440) * Support for additionalProperties in the C generator. * Support for additionalProperties in the C generator. * [docs] Enable Algolia search (#5472) * Fix #5420 add headers from configuration object (#5422) * Fix #5420 add headers from configuration object * Add baseOptions undefined checking #5420 * Update the samples and replace array to object #5420 * Update sample * [typescript] Clean up modelPropertyNaming across generators (#5427) * [typescript] Clean up modelPropertyNaming across generators Fixes https://github.com/OpenAPITools/openapi-generator/issues/2976 Generators without runtime models conversion use "original" property naming by default. It's still possible to change it via cli options Generators with runtime conversion keep using "camelCase" * Refactoring: use enum instead of string for modelPropertyNaming * Restore the original camelCase for var names, decouple it from property names * Swap toParamName and toVarName logic (looks like I've mistaken them) * Regenerate docs * Remove a no longer used private method * Added support for msvc builds in cpp-qt5-client generator (#5468) * Added support for msvc builds Moved GCC-specific compile flags to non msvc builds, and added equivalent flags for msvc. * CMakeLists condition cleanup * [all] Move feature set setter (#5460) When I originally implemented the feature set code, I added the getter/setter on DefaultCodegen and CodegenConfig as well as on GeneratorMetadata. GeneratorMetadata also includes the library variation features. When I went to add library-specific features, I realized the discrepancy. This removes the public setter from DefaultCodegen/CodegenConfig, and adds a protected modifyFeatureSet which accepts a lambda and hides the builder logic away in the method. This will be a breaking change for anyone who's created a custom generator in 4.2.3, so the impact is very limited. * [Swift5] small improvements to Objc compatibility (#5410) * [swift] make some small improvements * [swift][client] revert model to use allVars * PostProcessModelProperty with allVars * PostProcessModelProperty with vars * [swift] improve objc interoperability * [swift] fix swift4 for CI to pass * [swift] improve objc interoperability * [swift] improve objc interoperability * Swift - try to fix build * [swift] remove pods from git * [scala] [template] scala sttp client (#5429) * scala-sttp-client template * invoker for sttp fixed and tests added * clean up pet api test from redunant comments * docs updated * fix artefact name, model comments and redunant generic * code optimization * cross scala versions 2.11 2.12 2.13 * date serializers extracted and joda enabled as default * basic and bearer authorization added, apikey in query supported * [Ruby] Fix obsolete configuration of Rubocop and Rubocop's warns (#5417) (#5474) * fix obsolute configuration in generated .rubocop.yml * fix style of `expect` with block in generated ruby client's test code * update sample of ruby client * [scala] strip model class name for all scala generators (#5439) * stripped parameter enabled for all scala based generators * scala samples updated * docs generators updated * fix scalatra. regenerated by openapi3 script. manually removed enum default value from scalatra example due bug in schema extraction * [Scala][sttp] various improvements (#5475) * various improvements to scala sttp * update ScalaSttpClientCodegen.java * add windows batch file * test scala sttp in jdk8 * fix tempalte directory * Use the dataType if the baseType is not set (#5372) * Use the dataType if the baseType is not set * add tests for passing enum as parameter * updated requirements file in samples * Update spec to explicitly name objects and prevent `inline_object` * use the correct scripts to generate samples (`bin/openapi3/python-flask*`) * [python] Adds python oneOf/anyOf models + tests (#5341) * Adds oneOf + anyOf schemas, models and tests to python-experimental * Adds setUpClass and tearDownClass * Removes newline in method_init_shared.mustache * Regenerated v3 spec sample for python-experimental * Fxes test for discard_unknown_keys * Moves new models into existing spec, regen python-exp and go-exp * Also fix python-exp windows file * fix CVE-2020-8130 (#5483) * [go] Add Ptr method to const enum values (#5257) * fix rubocop warns in Ruby client's custom spec (#5488) * [C-libcurl] The name in API parameter should not be escaped even though it includes a C key word. (#5487) * [go-experimental] Support aliasing of API keys (#4940) * [go-experimental] Support aliasing of API keys * Use {{.}} inside condition * Use name instead of keyParamName for lookup * x-lookup to x-auth-id-alias * [java] Support aliasing of API keys (#4966) * [java] Support aliasing of API keys * Rebuild Java Jersey2 sample client * x-lookup to x-auth-id-alias * Regenerated * [cli][gradle] Validate now uses parseOptions w/setResolve (#5471) * [cli] Validate now uses parseOptions w/setResolve The validate command now uses ParseOptions#setResolve(true) to match how we parse in CodegenConfigurator and online's Generate. Without this option, the OpenAPI 3 parser skips the "resolve" block, which made lead to validations in the command not matching validations during generation. * [gradle] Validate now uses parseOptions w/setResolve The Graldle validate command now uses ParseOptions#setResolve(true) to match how we parse in CodegenConfigurator and online's Generate. Without this option, the OpenAPI 3 parser skips the "resolve" block, which made lead to validations in the command not matching validations during generation. * [kotlin]Fix ktor doesn't generate nullable types (#5258) * If not required, need `? = null` * run ./bin/kotlin-server-petstore.sh * Added `?` when value is `required` and `isNullable` * Rerun ./bin/kotlin-server-petstore.sh. But No differences * [C++] Add an option to allow having lowercase variables in models, Pistache: allow using reservedWords in models (#5434) * [C++][Pistache] Use reserved words to replace incorrect names discard old decision to truncate reservedWords * [C++][Pistache] Update struct model to use name instead of baseName * [C++][Pistache] Update Petstore sample * [C++] Add option to have lowercase variables * [C++] Update generated docs * [BUG] [JAVA | Spring] Cookie in parameter is not correctly generated (#5393) * Cookie in parameter is not correctly generated * gh-5386: Fix cookie parameter in * gh-5386: Fix cookie parameter in * gh-5386: Update test file * gh-5386: Fix cookie parameter in * gh-5386: Fix cookie parameter in * gh-5386: Regenerate samples * gh-5386: Fix test * Added Spring CookieValue tests Co-authored-by: Gonzalo * Add missing `@Generated` annotation. (#5384) The annotation is present on other generated files when using jaxrs-spec, but it missing on model classes. * [scala] [template] scala model property style (#5486) * Model property naming style generic for scala * scala templates based on abstractScala regererated * docs generators updated * property format tests * add Agoda as the user (#5494) * Hide timestamp in Scala Play server samples (#5495) * hide timestamp in scala play server output * add chameleon82 to scala tech committee * Add a link to tech blog tech.medpeer.co.jp (#5498) * Add links to blog posts about OpenAPI Generator (#5508) * Typescript array alias array (#4981) * Add failing tests for typescript type declaration * Refactor array and map child type string fallback * Add unaliasSchema to typescript getTypeDeclaration * TypeScriptRxjs: Use Blob as file type declaration This was inadvertantly changed in https://github.com/OpenAPITools/openapi-generator/pull/5266 * [core] Sanitize/underscore/camelize cache expiry (#5484) The helper methods for sanitize/underscore/camelize were recently updated to cache values in static maps. This would lead to a memory leak in hosted environments as the maps had no cleanup/expiry. This moves those cached entries to Caffeine caches with expiry based on last access to allow the edge-case performance improvement gains on very large documents, without the memory leak in hosted or embedded environments. * Update README.md * Add a link to the conference paper (#5510) * Add a link to the conference paper * fix author list * [Slim4] Add Data Mocker middleware (#4978) * [Slim4] Store response schemas * [Slim4] Add Data Mocker middleware * [Slim4] Enhance Slim router * [Slim4] Enhance config * [Slim4] Fix data format key in object mocking * [Slim4] Add tests for Data Mocker middleware * [Slim4] Add Mock feature documentation * [Slim4] Refresh samples * [Java][Spring][Spring-Cloud] Fix #5144 - Use conditional package declaration to avoid unnecessary dependencies (#5145) * FIX: Use conditional package declaration to avoid unnecessary dependencies * DEV: Adjusted sample ClientConfiguration.java for async spring-cloud * fix(php): no need to serialize collections, Guzzle does that, fix #2292 (#3984) * fix(php): only serialize collections if !explode, Guzzle handles the rest, fix #2292 * fix(php): update petstore samples Co-authored-by: Mahdi Dibaiee * [php] replace $collectionFormat with $style (#5517) * php - remove $collectionFormat * update php openapi3 petstore sample * [BUG][scala][template] scala generate java.math.BigDecimal instead of scala type (#5514) * [BUG] scala generate java.math.BigDecimal instead of scala type * update docs/generators * [PHP] complete support for form style (#5519) * [BUG][PHP] Parameter property style not fully implemented (related to comment on PR #3984) * [AUTOGENERATED][PHP] Sample Files * update jackson dependency to newer version (#5527) * Fix Swift4 CI tests (#5540) * comment out swift 4 order tests * comment out store tests * Test Dart petstore client in CircleCI (#5544) * test dart2 in circle ci (jdk7) * fix tests * update package * fix dart installation * Add serialization of ModelComposed (#5551) * Fixes kwargs typos, removes E501s (#5552) * Update generic model to support nullable properties (#5568) * [DOC] Add link to integration test wiki in CONTRIBUTING.md (#5570) * Add link to integration test wiki * Add link to integration test wiki * [Kotlin][client] fix file upload (#5548) * [kotlin] fix file upload * [kotlin] fix file upload * [kotlin] fix file upload * [kotlin][client] fix jackson integration * [kotlin] fix file upload * [kotlin] fix file upload * update doc * [Java] Fix exception when OAuth2 token URL is a relative URL (#5535) * Add support for case when OAuth2 token URL is a relative URL * Add support for case when OAuth2 token URL is a relative URL * run scripts under bin * [Java] fix runtime exception when there are multiple auth methods (#5530) * fix runtime exception when there are multiple auth methods * Refactor a bit so that it does not cause conflict with relative url token branch * [markdown] Fix broken links when generating markdown (#5569) * [markdown] Fix broken links when generating markdown The `api.mustache` file generates links to the markdown model files. These links were previously brokeen. Additionally, the defaultPackage for markdown is "/Models", so this looked pretty in the heading for model files. So this prefix has been stripped from the header in `model.mustache`. * Re-generate Petstore samples for markdown * typescript-angular: fix zone-js version for angular 8 (#5585) * Add a link to the slide (#5590) * [Swift] fix URLSession file upload (#5546) * [swift5] - fix URLSession file upload * [swift5] - fix URLSession file upload * [swift5] fix file upload * [swift5] - fix URLSession file upload * [swift] add unit tests for file upload * [swift] update samples copyright * [swift] add option for API prefix (#5567) * [swift] add option for API prefix * [swift] update docs * [haskell-http-client] update stack; exclude problem time versions (#5589) * [go-experimental] Do not generate HTTP signature unit test for every generated SDK (#5588) * Do not generate HTTP signature unit test for every generated SDK * Add golang 1.14 to CI environment * fix unit test issues * remove script commands that were commented out * add support for ed25519 private keys * PR to solve 2 open issues on enums: #5091 and #4293 (#5477) * PR to solve 2 open issues on enums: Issue 5091 needs to generate enums also when the enum is directly in a param to a API call, instead than in a model. I did that by copying and adapting enum code from *model* to *api* Issue 4293 needs to decorate enums, for when enum names or enum values are repeated over the yaml definition. * PR to solve 2 open issues on enums: Issue 5091 needs to generate enums also when the enum is directly in a param to a API call, instead than in a model. I did that by copying and adapting enum code from *model* to *api* Issue 4293 needs to decorate enums, for when enum names or enum values are repeated over the yaml definition. * Enums decorated: with {{projectName}}_{{classVarName}}_{{enumName}}_ in the models, with {{projectName}}_{{classVarName}}_{{enumName}}_ in the operations. * Changes to the c client: - Removed white space. - Removed ToJSON and FromJSON function for the enums, since they are not used - Sanitized project name in the .java file. For example, this solves a problem with the issue #2338, where the yaml file had title: "Skycoin REST API." * Changes to the c client: - Removed white space. - Removed ToJSON and FromJSON function for the enums, since they are not used - Sanitized project name in the .java file. For example, this solves a problem with the issue #2338, where the yaml file had title: "Skycoin REST API." * Adds parseFlattenSpec (#5526) * Adds parseFlattenSpec, updates tests and helper functions * Adds parseSPec invocation inside parseFlattenSpec * Scala-Akka: Add missing body to PATCH requests (#5605) * NodeJS - Adds missing keyword (#5606) * [jaxrs-cxf-cdi] Support PATCH httpMethod (#5574) Update the required CXF version to 3.1.2 since PATCH support appeared with this version. Add the cxf PATCH annotation to the imports so that the generated code when defining a PATCH api compiles. * fix default value for abstract scala and scalatra server impl (#5578) * [Java] Generated API class has wrong dataType and does not compile Issue (#5331) * add unit test assertion * add check for composed schema * add support for x-allOf-name * change x-allOf-name to x-all-of-name * Add more troubleshooting information * Add more troubleshooting information * Add more troubleshooting information * Add more troubleshooting information * [swift5] stop hiding network error (#5603) * [swift5] stop hiding network error * [swift5] stop hiding network error * [scala][templates] java 8 dates support (#5291) * [scala][akka-http-client] java8 dates support * scala-akka readme doc updated * DateSerializers renamed * rename serializers * move date-library option to abstractScala * generators docs updated * enum defined for date libraries * Backport to scala-http-client * fix scala-akka-client date serializers * fix typo in docs * switch scala templates to java8 (jsr-310) date library by default * update scala samples with java8 date library * update scala generators docs with java8 default date library * fix scala-play-server generator cli options as only java8 dateLibrary supported * fix scalaz DateTimeCodecs template to support java8 * scalaz ci test againt java7 removed as it generate scala 2.11.8 client which is java8 based * update doc * Adding Response Interceptor (#5500) * added Response interceptor for native clients * added Response interceptor for native clients * [k6] Add blog post about using the k6 generator (#5608) * [Kotlin] Remove kotlin-reflect dependency when not needed (#5502) * Remove kotlin-reflect dependency when using CodeGen * Update Kotlin tests * Regenerated unit test samples * Remove newline in generated build.gradle files * [typescript-fetch] add interfaces, withInterfaces (#5612) * typescript-fetch: interfaces, first draft * fix name in description * [scala] Regenerate akka sample (#5622) * scala-version 2.11.12 (#5618) * micheleISEP->michelealbano (#5625) * [Powershell] refactor the client generator (#5629) * add api client * add local variables * add configuration * add header/query/form parameter support * add partial header * add auth, fix parameters type * fix accept, content type * url query string * fix path, header * remove dep on C# client * fix method naming with package name * fix object * convert result from json * better response handling * remove tostring method * fix model doc * fix default module * generate api test files * better api, model tests * fix add pet * add appveyor * fix accept, content type * add petstore tests * fix form parameters * test delete * better file handling (upload) * better code sample * add package version, better doc * delete unused files * fix header parameters * clean up api client * update samples * support query parameter * better method and parameter naming * minor formatting change * better doc, fix cookie parameter * better doc * add api prefix support * better api nam prefix option * fix configuration * throw errors for required parameter * fix authentication * add try catch block to sample code * rename model * use debug, clean up comment * revise code * move bin script * update doc * add new file * better map support * [PowerShell] minor improvements and bug fixes (#5635) * add output type, minor format fix * minor test improvement * Port client updates to server (#5634) * Revert "scala-version 2.11.12 (#5618)" This reverts commit 6b984a926a0f99120a4ad80cef73bee19f8614cd. * update release date * Handle negative response from the server (#5649) * Fix integration tests (Travis, CircleCI) (#5672) * fix php tests * fix scala tests * update ts angular v6 rest * fix user create test * fix spring cloud test * comment out user delete * fix angular v7 tests * fix user test * fix tests * fix go exp tests * commented out delete user tests * comment out delete user tests in go openapi 3 * fix clojure tests * [PowerShell] Fixes typo (#5648) * Solving issue #5623 and supporting bools for C client label:"Client: C" (#5624) * Removed stray "printf"s in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java * Support for booleans in C client * Update README.md * Change to C API mustache files to solve issue #5623 * Debugging of C's modle-body.mustache, as suggested by ityuhui * Final changes suggested by ityuhui * [PowerShell] Fix map type (#5638) * fix map type * remove output type, fix appveyor * test macos * comment out failing scala test * fix typo: configuration * Revert "comment out failing scala test" This reverts commit 1dcf84ffcbb7ab520938ae7c75d60a8329f71478. * [powershell-experimental] Protects against stackoverflow when OAS spec has circular references (#5646) * protects against stackoverflow when OAS spec has circular references * protects against stackoverflow when OAS spec has circular references * Adds configuration option to skip certificate check. Fixes a typo. Fixes an issue which was restricting from cookie to get consumed (#5657) * [k6] bugfixes to improve the output script (#5614) * [k6] Skip appDescription escaping * [k6] Fix variable identifier in output * [k6] Fix bug with reserved words handling * [C][Client] Check the pointer before deleting operation to avoid core dump label:"Client C" (#5626) * [C-libcurl] Check the pointer before deleting operation to avoid core dump * [C-libcurl] Check the pointer before deleting operation, update sample * [kotlin][client] Add Jackson to interface properties and remove extra line feed (#5459) * [kotlin][client] Ensure Jackson annotations are consistent with interface vars * [kotlin][client] Rebuild samples * [kotlin][client] Some kotlin client enhancements - Don't use JsonFormat for Date objects, this should be controlled via a custom serializer/deserializer or a turning on and off serialization features of Jackson. I've updated the jacksonObjectMapper config to write the dates as strings, which I think was intended in the original commit. https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/SerializationFeature.html#WRITE_DATES_AS_TIMESTAMPS https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/cfg/MapperConfig.html#getDateFormat-- - Dont' use @JsonFormat(shape = JsonFormat.Shape.OBJECT) for enums. This causes Enums to be formatted as objects with an internal "value" field. In reality, OpenAPI enums are just strings without properties and should be treated as a string. https://www.baeldung.com/jackson-serialize-enums#2-enum-as-json-object - Add's Kotlin use site annotation @get: to JsonProperty for parent interface properties. Otherwise Kotlin will warn: "This annotation is not applicable to target 'member property without backing field or delegate'" - Add's JsonTypeInfo annotations to interfaces for inheritance. This was copied verbatim from the kotlin-spring generator. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-spring/typeInfoAnnotation.mustache * [kotlin][client] Rebuild kotlin samples * Remove scala version in parent pom (#5647) * [asciidoc] Allow the inclusion of additional documentation to t… (#5260) * [asccidoc] Allow the inclusion of additional documentation to the asccidoc generated Resolves #5228 * [jaxrs-reasteasy-eap] Fix invalid Bean Validation annotations for Longs (#5659) * fix issue #5658 * update samples * [PowerShell] Test powershell petstore client in Appveyor (#5674) * remove scala version in parent pom * test ps petstore in appveyor * fix command * build and import * fix import module * fix import * skip module import * run multiple commands * move to test script * test ps exit * fix exit * check last status code * clean tests * exit last code * add import * change dir * skip build failure * fix check * trigger build failure * fail fast * restore c# test * new line comment * add powershell exp to ensure up to date script * [PowerShell][Experimental] Better docstring (#5688) * add docstring to powershell module * add doc string * Nodejs express js packages update (#5675) * Updated to new nodejs packages, depending heavily on express-openapi-validator. Requires quite a change in code. Updated the business-logic in the controllers/Controller.js file. Logger now records also timestamp of events. Files are uploaded according to definition in config.js file * Removed commented-out code; Changed openApi document extensions to suit new express-openapi-validator definition; multipart and file uploading is supported now; Automatic response returns the values the were sent in the request * fixed README documentation, fixed a mistage in package.json/mustache * added generated files that were created when running the ./bin/test file * [go-experimental] Fix nullable support (#5414) * Fix nullable support in go-experimental client * Fix support for models with parents and container fields * Make sure that oneOf interfaces serialize properly even if they're required (non-pointers) on other models * Spaces => tabs * Regenerate samples * Make some methods of nullables pointer-receivers, add tests * Improve the Get/Set logic to make usage more convenient * Address review * [kotlin][client] make base path globally configurable (#5450) * [kotlin][client] make base path configurable * [kotlin][client] update pet project * [kotlin][client] set default base path * [kotlin][client] set default base path * [kotlin][client] set default base path * Add michelealbano to C technical committee (#5692) * [Go][Experimental] Rename extensions from x-basetype to x-go-base-type (#5691) * rename go vendor extension * update go exp petstore samples oas3 * comment out powershell petstore in uptodate script * remove processing of http_signature_test.mustache (#5696) * Fix generation of oneOf interfaces for oneOf usage in properties (#5400) * Fix generation of oneOf interfaces for oneOf usage in properties * Only generate oneOf interface models when oneOf is defined * use basic parsing (#5702) * [python/asyncio] explicitly close client session via async context manager (#5621) * [gradle] Include engine option for handlebars generation (#5686) * [codegen][Go] Fix compilation error of generated go code when schema is free form object (#5391) * Fix code generation for free-form objects in go-experimental * Execute scripts in bin directory * Add more use cases for open-ended types * Add more use cases for open-ended types * Add more use cases for open-ended types * add code comments * Better name for test properties * handle scenario when type is arbitrary * handle interface{} scenario * handle interface{} scenario * add helper function isAnyType * isAnyType function * implementation of isAnyType function * fix javadoc issue * handle interface{} scenario * use equals comparison instead of == * merge from master * Add code documentation * add code comments, remove unused min/max attribute, fix equals method * Handle 'anytype' use case * add code comments * override postProcessModelProperty to set vendor extension * Use vendorExtensions.x-golang-is-container * fix compilation error of generated code * fix compilation error of generated code * fix compilation error of generated code * [Java] Update version of maven-surefire-plugin (#5509) * use more recent version of maven-surefire-plugin * use more recent version of maven-surefire-plugin * higher debug level for troubleshooting ci issue * temporarily increase debug log to help troubleshoot * Use local instance of pet store service for unit test purpose * Add more logging to troubleshoot unit test failures * Add more logging to troubleshoot unit test failures * Add more logging to troubleshoot unit test failures * Add more logging to troubleshoot unit test failures * Add more logging to troubleshoot unit test failures * use random ID for Java unit test instead of fixed id * add code comments and specify URL for java unit test * reenable quiet argument * fix java unit test issues * fix java unit test issues * Revert "fix java unit test issues" This reverts commit e8508416ff0f2aeb568e3f916b013dc967390f74. * fix java unit test issues * Generator for JavaScript/Apollo Client (#5645) Co-authored-by: William Cheng * Add yutaka0m to Kotlin Technical Committee (#5716) * Add Scala client scripts to ensure-uptodate process (#5712) * add scala client to ensure-upto-date * new scala-akka petstore oas3 folder * regenerate scala akka oas2 petstore * remove script * Minor improvments to JS apollo generator (#5714) * minor improvments to js apollo generator * comment out apollo * [Rust Server] Handle text/xml correctly (#5660) * [Rust Server] Handle text/xml correctly Treat application/xml the same as text/xml as per RFC 7303 * [Rust Server] Add test for text/xml * Update samples * 4.3.0 release (#5721) * update samples (#5722) * 5211 - Use allVars instead of vars for Kotlin client (#5396) * [C++] [Qt5] fixed cpp-client-qt5 HttpRequestWorker requests crashing on timeout... (#5651) * - fixed cpp-client-qt5 HttpRequestWorker requests crashing on timeout when they have actually NOT timed out (were calling back into a deleted struct). * #minor fixes after review * Regenerate changed files Co-authored-by: valentin Bisson Co-authored-by: etherealjoy * Fix SSL setting in checkout script (#5725) * fix ssl setting in checkout script * add check for sbt-openapi-generator * [C] fix decode funtion (#5642) * fix function names and add parameter to return decoded bytes length from base64decode function * format base64decode function to avoid unnecessary malloc and fix wrong length assigning * update the pointer assigning for some reason var++ / *var++ cannot be done on int *var, hence making a local variable which is incremented and at the end it is assigned to the pointer. * Update bump.sh to go SNAPSHOT to version (#5727) * Fix CI failures (#5734) * update ci to use petstore 1.0.4 * comment out test * comment out test * comment out update user test * comment out more tests * use latest petstore * comment out updatePetWithForm * comment out update pet test * fix file path in release_version_update_docs (#5724) * better appveyor test (#5739) * better readme, type mapping, new option (#5740) * Remove warning for unused camel case vendor extension for Qt5 client and server (#5731) * [PS][Experimental] Add multiple server support (#5741) * code comment * add get host setting * add multiple server support * add default headers support (#5746) * [C][Client] Support SSL client authentication for the c client (#5719) * [C][Client] Support SSL client authentication * [C][Client] Support SSL client authentication, update sample * [kotlin] Fix #5247 incorrect enum parameter type for arrays (#5435) * [Erlang-Server] security definition context changes don't propagate to handler (#5751) * Map Merge Context & Params handler requires context and params to be merged before returned to user defined request_handler. * post build & shell script * Delete VERSION * [PS][PowerShell] fix passthru, use switch instead of bool (#5768) * fix passthru, use switch * remove line * comment out kotlin vertx server test (#5767) * add support for common verbs (#5771) * fix request.on_complete message when tempfile is nil (#5745) * fix request.on_complete message when tempfile is nil * update faraday client sample * add openapi3 client samples * use prepare instead of new (#5773) * use Initialize instead of prepare (#5777) * add map example (#5778) * [PS][Experimental] Better common verb handling (#5783) * better common verb handling * better debugging * add option to customize common verb * [cli][docker] Better expose version/sha information of builds (#5736) * [cli] Some CLI improvements… * Introduce --version * Introduce --help * Add --sha to version command for short SHA display * Output Version and SHA details * In new --version output, display repo and doc site Additional cleanup to suppress warnings and code quality. * [docker] Adds labels for metadata This adds image labels to store metadata on the online and cli docker images, using standard labels: * org.opencontainers.image.created * org.opencontainers.image.revision * org.opencontainers.image.title * org.opencontainers.image.version These can be inspected via 'docker inspect IMAGE_NAME' and may be useful in tooling/automation or bug reports submitted by users. For more details on these labels, see: https://github.com/opencontainers/image-spec/blob/master/annotations.md * Include version --full for equiv to --version * [cli] Add --global-property for -D replacement (#5687) -D option has been deprecated as it was previously used to: * Pass "system properties" * Pass additional properties This was confusing because we already have --additional-properties and because Java System Properties are passed as -D before program arguments. Confusion around the -D option had existed for some time, but when we introduced the thread-safe GlobalSettings to avoid overwriting Java System Properties, we created a hard break from Java System Properties in the generator. This also disconnected the previous "system properties" from accepting additional properties. Once these newly deprecated methods are removed, we will have a clear separation of concerns between: * Java System Properties * Global generator properties (used as workflow context) * Additional properties (used as generator options) This commit marks multiple places for cleanup in 5.0. These will be breaking changes, and lower effort to break in 5.0 with deprecation warnings now rather than adding sibling properties throughout the code and potentially introducing logic errors. * [dart-dio] Fixes --model-name-suffix having no effect (#5669) Fixes #5409 * [go-experimental][go][client] Remove unreachable code in go client API methods (#5611) * [go-experimental][go][client] Remove unreachable code in go client API methods * Properly regenerate all samples * please add openVALIDATION Project to readme (#5534) * added openVALIDATION Project to readme * Update README.md Co-Authored-By: Akihito Nakano Co-authored-by: Akihito Nakano * [Csharp-client] Complex form parameters are not serialized as application/json (#5787) * [csharp-client] Complex form parameters are now correctly serialized as json. Reference: http://spec.openapis.org/oas/v3.0.3#special-considerations-for-multipart-content * Updated bin/windows csharp sample generation scripts to point to the correct directories * Updated csharp samples Co-authored-by: Olivier Leonard * fix scala-akka java8 serializers (#5742) * fix scala-akka java8 serializers * regenerate samples for akka-http * [typescript-axios][client] Unnecessary imports occurs when using withSeparateModelsAndApi (#5797) * add ts-ignore * add petstore sample * use write verbose in auth, better api doc (#5804) * [PS][Experimental] add withHttpInfo support, fix "null" return (#5811) * add with http support * use full name in tests * using full name in test * skip type check * [PS][Experimental] Add tests for array of object in response (#5814) * debugging array response * fix find pet tests * better tests to ignore order * [codegen] Use once(LOGGER) to reduce amount of identical warning messages (#5808) * Warn once instead of many times when the log statement does not have contextual information * Warn once instead of many times when the log statement does not have contextual information * make name cache configurabl (#5775) * [codegen] Cachesize config seconds (#5816) * make name cache configurable * Address review comments * [Python-experimental] Documentation enhancement for oneOf schema and minor err msg improvement (#5791) * Add documentation to generated code * Improve error message * Improve documentation * Improve documentation * Improve documentation * Improve documentation * Improve documentation * Improve documentation * Run sample scripts * Address review comments * Address review comments * Fix problem in python error message * rename hostsetting, validate base url (#5821) * fix array return (#5822) * Scala akka-http server (#5758) * Scala akka-http server base implementation * [scala-akka-http-server] petStore samples * Improved the formatting of generated files * Updated scala-akka-http server samples * [scala-akka-http-server] the groupId, artifactId and artifactVersion default value are used as intended. * Fixed the default operation not being correctly generated on parameterless operations * Added build.sbt.mustache supporting file * Updated scala-akka-http server samples * ScalaAkkaHttpServer: Fixed a String.format call to use Locale.ROOT for locale * [scala-akka-http-server] Fixed defaultValue being escaped during generation * Added scala-akka-http.md * Replaced all "⇒" character with "=>" to retain compatibility with scala 2.13 * [scala-akka-http] Added a config option akkaHttpVersion It's set in the generated build.sbt. * Updated scala-akka-http server samples * [scala-akka-http] More accurate akkaHttpVersion parsing * Updated scala-akka-http.md * [scala-akka-http] Changed the akka-http version check to fix the generation of StringDirectives * Updated scala-akka-http samples * updated scala-akka-http.md Co-authored-by: Olivier Leonard * Minor improvements to scala akka server (#5823) * minor improvements to scala akka server * add samples * update doc * Update swagger parser to 2.0.19 (#5413) * update swagger parser to 2.0.18 * fix online server exception * Revert "fix online server exception" This reverts commit fe3cb5221f362c00b176fa81411eaf368f0e446d. * update parser to 2.0.19 * [jaxrs-cxf-cdi] fix allOf equals and hashCode (#5756) When generating model that use allOf, the equals and hashCode methods must take the parent class into account. * [BUG] [KOTLIN] Fix default value generation for Kotlin Strings (#5776) * fix default value generation for kotlin * add updated pet templates * Revert "add updated pet templates" This reverts commit 7e8168ad * regen pet store projects code * tests for models for C-libcurl generator (#5699) * First try to generate unit tests for the models of the C-libcurl client. Models into models are not supported yet. * Added unit tests for the modules of the C-libcurl client to the git repository. * Support for objects having other objects as properties, for the C-libcurl client generator * Proper formatting of generated code * use allVars to cover all properties (#5835) * support enum in parameters (#5838) * [C++] [Qt5] [Client] fixed cpp-client-qt5 HttpRequestWorker contentCompression variables initialization (#5834) When contentCompression is not enabled, the variables isRequestCompressionEnabled and isResponseCompressionEnabled in HttpRequestWorker are not being initialized. Without initialization the compress function could be called and the request content could be an empty QByteArray instead of original request body. * minor fix to http basic auth (#5839) * Scala akka http server - normalization of some vendor extensions (#5829) * [scala-akka-http-server] Normalized vendor extension "paths" to "x-paths" * [scala-akka-http-server] Normalized vendor extension "hasDefaultValue", "isDefault", "specificMarshallers", "fileParams", "nonFileParams" Co-authored-by: Olivier Leonard * Add Bouill to the Scala technical committee (#5843) * C client generator improvements to support petstore. Solves #5836 (#5837) * C client generator improvement to support: openapi-generator/modules/openapi-generator/src/test/resources/3_0/petstore.yaml * Improvements to the C client generator: - moved base64* from apiClient.c to binary.h/binary.c - changed CR/LF to LF in binary.h/binary.c * C client generator: better support for base64encode / base64decode * Add openapi.yaml file to Java clients (#5765) * Add openapi.yaml file to Java client * Move supporting template file to Java root * Update petstore clients * [codegen] Fix 'super.HashCode' for oneOf and allOf Implementations (retry) (#5830) * Added hasVars after completion of all model post-processing (#5587) * Post ensure-up-to-date * Update to check the size of vars and not assume non-null * update mysql samples * Add default case to handle response code (#5825) * add default case to handle response code * fix default response code * add test for isDefault * fix user id in scala tc * Fix for Issue #4840 [BUG][JAVA][spring-mvc] Generated Code for Map of Maps Return Type does not compile (#5240) * add parent for allOf only (#5851) * Add pythonSrcRoot option to python servers (aiohttp/flask/blueplanet) to support src/ layout projects [and reenable/fix all python server tests] (#5423) * python server: Add pythonSrcRoot option This will allow the python project to be in a subdirectory (as specified in pythonSrcRoot). That could mean following the src layout with sources under src/ or lib/. Multi-language projects might use a sub directory like python/, or whatever makes sense for the project. By default, the pythonSrcRoot is "", meaning the existing behavior is the default. * python server: update template files to support pythonSrcRoot * python server: update docs to add pythonSrcRoot option * python server: add pythonSrcRoot sample script * python server: build sample srclayout project * [Python] copy test files preserving history * [Python] Make a conflict to preserve file copy history * [Python] customize pom.xml for src layout tests * [Python] add python-aiohttp-srclayout tests * [Python] Fix server tests by updating requirements Reverts the PR that disabled python2 server tests: https://github.com/OpenAPITools/openapi-generator/pull/4949 Reverts commits that disabled python3 server tests: 9adfedbfbb45c7059e64b3d9a285710bded4fb62 17ee990baaa80585242c7a07d64e2be4888fcfd0 Issue about the python 3 tests: https://github.com/OpenAPITools/openapi-generator/issues/5235 I couldn't find an issue about the python2 tests being disabled. I'm guessing build errors like the following were the trigger: https://travis-ci.org/github/OpenAPITools/openapi-generator/builds/634238181 Let's see what breaks! * [Python] Copy setup.py to python-aiohttp * [Python] Save history while copying setup.py to python-aiohttp * [Python] Add aiohttp server setup.py * [Python] Fix python server tests with src layout * [Python] bump Flask-Testing version * [Python] Pin pyyaml for py2.7 flask server * [Python] simplify flask server requirements * consolidate server tests * [Python] rebuild python server samples * [Python] Fix python server requirements for older pythons Documented minimum python version for our aiohttp server is 3.5. Documented minimum python version for our flask server is 3.4. Connexion 2.3 is the last version to support python 3.4 and 3.5, so fix the version pinning to correctly select <=2.3 for these EOL python versions. Newer pythons should get the latest if possible as there many relevant bug fixes. Werkzeug also needs to be pinned for these old versions in the aiohttp server just like for the flask server. 3.4 and 3.5 are EOL. We really should increase the minimum supported version, but that is for another PR to do. * stop error globally (#5858) * [PS][Experimental] Add validations to model (#5842) * add validations to model * better error message * improve validation * Updates to allow the setting of the dateTime format string (#5763) * [PS] Select Content-Type in the response (#5872) * better return type handling * update tempalte * better documentation * fix greater than * various enhancement to ps exp generator (#5875) * [C#] dependency upgrade (#5870) * Updating packages version (#5313) * Add support to RestSharp version 106.10.1 Restsharp 106.10.1 needs the Content Lenght as a parameter to AddFile method * Updating RestSharp Version Updating RestSharp Version * Update netcore_project.mustache * Update netcore_testproject.mustache * Update Project.mustache * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Execute task async obsolete Use ExecuteAsync instead * update csharp samples Co-authored-by: William Cheng * [csharp] Library upgrade fix (#5848) * On .net45 framework, Restsharp version is updated to 106.10.1 Otherwise, it stays on version 105.1.0 * Added additionalProperties for library versions and target frameworks * Removed unused properties * Added an additional property to test for a specific version of RestSharp * Updated csharp samples * Fixed nuspec.mustache to use library specific additional properties * Updated csharp samples * Updating CI/samples.ci csharp petstore test project file. * Updated csharp.md Co-authored-by: Olivier Leonard * [csharp-client] Restored tests on csharp samples (#5879) * Restored tests on csharp samples * Restored a reference to the file used to test file uploads Co-authored-by: Olivier Leonard * update samples Co-authored-by: Igor Quirino Co-authored-by: Bouillie <34162532+Bouillie@users.noreply.github.com> Co-authored-by: Olivier Leonard * [Csharp-client] Complex form parameters are not serialized as application/json (#5849) * [csharp-client] Complex form parameters are now correctly serialized as json. * Updated csharp samples Co-authored-by: Olivier Leonard * docs: removes Nico from technical committee (#5883) * [PS] better handle special variables (#5885) * add variable * fix reserved words * update ps doc * [PS] add file post-processing to the PowerShell generator (#5864) * add post process to ps generator * add import * fix merge issue * consolidate header selection functions (#5889) * [Java-client] Add maven-compiler-plugin in pom.xml and enable linter checks by default (#5866) * Add maven-compiler-plugin plugin in Java pom.xml and enable linter checks by default * Add maven-compiler-plugin plugin in Java pom.xml and enable linter checks by default * Update enum.mustache (#5793) https://github.com/OpenAPITools/openapi-generator/issues/5792 * Update modelGeneric.mustache (#5378) * Update modelGeneric.mustache If maxlength is specified for a property type enum it there should be .ToString() appended before length check * ran the csharp petstore bar and updated the file Co-authored-by: Shweta Shukla * Fix Scala sttp generator packages (#5890) * Fix Scala sttp generator packages * Change package to parameterised * [Dart] Fix "basic" auth method and Add Bearer token support (#5743) * added auth check and lint * fixed basic auth condition * Added bearer auth * updated samples * update dart petstore samples Co-authored-by: William Cheng * Add date time format annotation on pojo for model query parameters (#5437) * Add date time format annotation on pojo for model query parameters * Regenetare samples * update spring samples Co-authored-by: William Cheng * [mysql] Add basic SQL queries (#5757) * Add basic SQL queries template * Add namedParametersEnabled option * Move model related SQLs into Model folder * Update README template * Refresh samples * [enhancement] [jaxrs-spec] Add builders to models (#4930) * Update formatting in jaxrs-spec POJOs * Add generateBuilders option * Update formatting in jaxrs-spec POJOs * Disable the builders generation by default * Ensure samples are up-to-date * Revert newline change * Run ensure-up-to-date * update doc * fix merge conflicts Co-authored-by: Artem Shubovych Co-authored-by: William Cheng * Update generated build files for REST Assured (#5873) * REST Assured 4.3.0 * Jackson 2.10.3 * Gson 2.8.6, GSON-Fire 1.8.4 * Okio 1.17.5 * Joda-Time 2.10.5 * ThreeTenBP 1.4.3 * Added missing dependencies for Bean Validation * Added missing dependencies for `@Generated` annotation * Refresh REST Assured sample project * [Java][Feign] Bug fix in @Param annotation (#5250) * FIX-5249 fix @Param annotation for Feign-client code generation Use paramName instead of baseName in order to make mapping in @Headers section fit the param-value. * update samples * FIX-5249 fix @Param annotation for Feign-client code generation Use paramName instead of baseName in order to make mapping in @Headers section fit the param-value. Co-authored-by: Christoph Preißner Co-authored-by: William Cheng * [Java] Increase java compiler stack size to handle large files (#5901) * increase java compiler stack size to handle large files * increase java compiler stack size to handle large files * Added emineo to list of companies on website (#5905) * add emineo to the list * [swift5] fix warning (#5900) * update bitwise config (#5904) * [Java] Discriminator lookup should not be case insensitive by default (#5894) * Add 'discriminatorCaseSensitive' property * Discriminator value lookup should not be case insensitive * fix typo * run scripts * execute ./bin/utils/export_docs_generators.sh * fix discriminator mapping, add code comments * minor fix to users.yml * Add a link to optim blog post (#5922) * [Java] Fix inclusive max validation (#5908) Co-authored-by: erikmolin * add bearer auth support to csharp netcore (#5921) * [Python][aiohttp] create venv as rule (#5913) * create venv as rule * create venv as rule II * Fix for Result Model Name collision (#5923) * Fix for Result Model Name collision * Run Scripts Co-authored-by: Sebastian Ohm * [Dart] Remove content type from header when content type is not specified (#5752) * accept empty content type * fixed test * updated samples * additional comment out * update dependency for java client (#5926) * Update axios dependency to the new minor version 0.19.0 (#5867) * Update axios dependency to 0.19.0 Axios (version 0.18.0) used by typescript-axios generator is more than two years old (released in Feb 2018). Axios 0.19.2 released earlier this year contains a lot of fixes and functionality, I recommend updating to 0.19.2. * Ran ./bin/typescript-axios-petstore-all.sh to update package.json in ./samples Co-authored-by: Chandra Yalangi * fixed README/doc of bearer auth support for csharp-netcore (#5931) * fix duplicated semi-colon in c# model (#5934) * [Python-experimental] Use DER encoding for ECDSA signatures, add parameter to configure hash algorithm (#5924) * Use DER encoding for ECDSA signatures * Use DER encoding for ECDSA signatures * Use DER encoding for ECDSA signatures * Use DER encoding for ECDSA signatures * fix python unit tests for http message signature * Fix error message * format python code * format python code * [Python-experimental] Fix TypeError: unhashable type: 'list' (#5810) * handle scenario when value is a list, fix TypeError: unhashable type: 'list' * Add __hash__ function * use list instead of set * use list instead of set * use list instead of set * use list instead of set * use list instead of set * use list instead of set * [python/asyncio] fix passing proxy parameters to aiohttp (#5943) * [C][Client]Fix data lost when libcurl write-data callback function is called multiple times (#5828) * [C][Client]Fix the defect of data lost when libcurl write-data callback function (configured by CURLOPT_WRITEFUNCTION) is called multiple times. * [C][Client]Fix data lost when libcurl write-data callback function is called multiple times (Reset count) * [typescript-axios][client] Allow apiKey type Promise. (#5953) * change apiKey type * recreate sample * Add YITU Technology to the user list (#5967) * add yitu to the user list * use yitu technology * Use model as body param for generateAliasAsModel (#4569) * generateAliasAsModel: Use model name as body param * Update samples * resolve merge conflicts in the core generator files * fix merge conflicts in pom.xml * Resolve Elm merge conflicts * [Rust Server] Fix up merge conflicts * Update samples * [Rust Server] Add debug log for rust-server-petstore.sh * update samples * update more samples * fix dart openapi-generator version * remove deprecated c# files * update meta codegen * fix port in pom.xml * fix port in sample * update jaxrs cxf version Co-authored-by: sunn <33183834+etherealjoy@users.noreply.github.com> Co-authored-by: dwlabcube <46682038+dwlabcube@users.noreply.github.com> Co-authored-by: Herve DARRITCHON Co-authored-by: Akihito Nakano Co-authored-by: Johnny Peck Co-authored-by: Michele Albano Co-authored-by: Jim Schubert Co-authored-by: Nikita Co-authored-by: Alexey Makhrov Co-authored-by: val Co-authored-by: Bruno Coelho <4brunu@users.noreply.github.com> Co-authored-by: Aleksandr Nekrasov Co-authored-by: Akira Tanimura Co-authored-by: Justin Co-authored-by: Justin Black Co-authored-by: Jiri Kuncar Co-authored-by: Hui Yu Co-authored-by: Yutaka Miyamae <48900426+yutaka0m@users.noreply.github.com> Co-authored-by: Mateusz Szychowski (Muttley) Co-authored-by: Jorge Rodriguez Co-authored-by: Gonzalo Co-authored-by: ChristianCiach Co-authored-by: Bodo Graumann Co-authored-by: Yuriy Belenko Co-authored-by: Daniel Klessing Co-authored-by: copypasta-g <53397163+copypasta-g@users.noreply.github.com> Co-authored-by: Mahdi Dibaiee Co-authored-by: Sebastien Rosset Co-authored-by: siada Co-authored-by: Samuel Hoffstaetter Co-authored-by: Esteban Gehring Co-authored-by: Jon Schoning Co-authored-by: Marcin Kubala Co-authored-by: anoohya-n <51289018+anoohya-n@users.noreply.github.com> Co-authored-by: Antoine Reilles Co-authored-by: Clemens Angermann Co-authored-by: Mostafa Moradian Co-authored-by: Adam Co-authored-by: Lars Hvam Co-authored-by: sullis Co-authored-by: Vikrant Balyan Co-authored-by: Matt Traynham Co-authored-by: LEZIER-S2 <60382243+LEZIER-S2@users.noreply.github.com> Co-authored-by: Thomas Enderle Co-authored-by: YishTish Co-authored-by: Slavek Kabrda Co-authored-by: Tomasz Prus Co-authored-by: Erica Kastner Co-authored-by: Richard Whitehouse Co-authored-by: valentin Bisson Co-authored-by: etherealjoy Co-authored-by: Hemant Zope <42613258+zhemant@users.noreply.github.com> Co-authored-by: Even André Fiskvik Co-authored-by: ehansen31 Co-authored-by: Timur Platonov Co-authored-by: Josh Burton Co-authored-by: Ilja leyberman <7ilya@gmx.de> Co-authored-by: Bouillie <34162532+Bouillie@users.noreply.github.com> Co-authored-by: Olivier Leonard Co-authored-by: tanmen Co-authored-by: Alex Buchkovsky Co-authored-by: Natan Laverde Co-authored-by: Nicholas Muesch Co-authored-by: jburgess <11861789+jburgess@users.noreply.github.com> Co-authored-by: emileonhardt <40421857+emileonhardt@users.noreply.github.com> Co-authored-by: Jacob Floyd Co-authored-by: Igor Quirino Co-authored-by: Nico König Co-authored-by: https://gitlab.com/selankon Co-authored-by: Shweta Shukla <25539662+shwetashukla@users.noreply.github.com> Co-authored-by: Shweta Shukla Co-authored-by: Bartek Kowalik Co-authored-by: Shinya Sugmoto <34866626+gasugesu@users.noreply.github.com> Co-authored-by: Artem Shubovych Co-authored-by: Artem Shubovych Co-authored-by: Jochen Schalanda Co-authored-by: Chr1st0ph Co-authored-by: Christoph Preißner Co-authored-by: Erikmolin Co-authored-by: erikmolin Co-authored-by: Nicolas Homble Co-authored-by: Sebastian <63457660+sebohdev@users.noreply.github.com> Co-authored-by: Sebastian Ohm Co-authored-by: chandra-gh <63366477+chandra-gh@users.noreply.github.com> Co-authored-by: Chandra Yalangi Co-authored-by: Fabian Freund Co-authored-by: Erik Timmers --- Gemfile.mustache | 2 +- api_client.mustache | 12 +++++++----- api_client_spec.mustache | 2 +- rubocop.mustache | 14 ++++---------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Gemfile.mustache b/Gemfile.mustache index 69255e559f7c..c2e3127cdcfe 100644 --- a/Gemfile.mustache +++ b/Gemfile.mustache @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem 'rake', '~> 12.0.0' + gem 'rake', '~> 13.0.1' gem 'pry-byebug' gem 'rubocop', '~> 0.66.0' end diff --git a/api_client.mustache b/api_client.mustache index 5d263ece7e34..f3139eaa46eb 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -158,11 +158,13 @@ module {{moduleName}} tempfile.write(chunk) end request.on_complete do |response| - tempfile.close if tempfile - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" + if tempfile + tempfile.close + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + end end end diff --git a/api_client_spec.mustache b/api_client_spec.mustache index 364c60419c4f..a079cc9fd350 100644 --- a/api_client_spec.mustache +++ b/api_client_spec.mustache @@ -150,7 +150,7 @@ describe {{moduleName}}::ApiClient do end it 'fails for invalid collection format' do - expect{api_client.build_collection_param(param, :INVALID)}.to raise_error(RuntimeError, 'unknown collection format: :INVALID') + expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID') end end diff --git a/rubocop.mustache b/rubocop.mustache index 0ef33ce5e322..df46058490d0 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -14,12 +14,6 @@ AllCops: Style/AndOr: Enabled: true -# Do not use braces for hash literals when they are the last argument of a -# method call. -Style/BracesAroundHashParameters: - Enabled: true - EnforcedStyle: context_dependent - # Align `when` with `case`. Layout/CaseIndentation: Enabled: true @@ -46,7 +40,7 @@ Layout/EmptyLinesAroundMethodBody: Layout/EmptyLinesAroundModuleBody: Enabled: true -Layout/IndentFirstArgument: +Layout/FirstArgumentIndentation: Enabled: true # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. @@ -57,7 +51,7 @@ Style/HashSyntax: # extra level of indentation. Layout/IndentationConsistency: Enabled: true - EnforcedStyle: rails + EnforcedStyle: indented_internal_methods # Two spaces, no tabs (for indentation). Layout/IndentationWidth: @@ -123,7 +117,7 @@ Layout/Tab: Enabled: true # Blank lines should not have any spaces. -Layout/TrailingBlankLines: +Layout/TrailingEmptyLines: Enabled: true # No trailing whitespace. @@ -131,7 +125,7 @@ Layout/TrailingWhitespace: Enabled: false # Use quotes for string literals when they are enough. -Style/UnneededPercentQ: +Style/RedundantPercentQ: Enabled: true # Align `end` with the matching keyword or starting expression except for From c3c72478bd8b30833c4b6393950500ca5eb38611 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 22 Apr 2020 11:59:27 +0800 Subject: [PATCH 55/86] Revert "Sync master to 5.0.x (#5968)" This reverts commit 90dd7a03418ff4554ae8351b325eb86ee5794e92. --- Gemfile.mustache | 2 +- api_client.mustache | 12 +++++------- api_client_spec.mustache | 2 +- rubocop.mustache | 14 ++++++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Gemfile.mustache b/Gemfile.mustache index c2e3127cdcfe..69255e559f7c 100644 --- a/Gemfile.mustache +++ b/Gemfile.mustache @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem 'rake', '~> 13.0.1' + gem 'rake', '~> 12.0.0' gem 'pry-byebug' gem 'rubocop', '~> 0.66.0' end diff --git a/api_client.mustache b/api_client.mustache index f3139eaa46eb..5d263ece7e34 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -158,13 +158,11 @@ module {{moduleName}} tempfile.write(chunk) end request.on_complete do |response| - if tempfile - tempfile.close - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" - end + tempfile.close if tempfile + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" end end diff --git a/api_client_spec.mustache b/api_client_spec.mustache index a079cc9fd350..364c60419c4f 100644 --- a/api_client_spec.mustache +++ b/api_client_spec.mustache @@ -150,7 +150,7 @@ describe {{moduleName}}::ApiClient do end it 'fails for invalid collection format' do - expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID') + expect{api_client.build_collection_param(param, :INVALID)}.to raise_error(RuntimeError, 'unknown collection format: :INVALID') end end diff --git a/rubocop.mustache b/rubocop.mustache index df46058490d0..0ef33ce5e322 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -14,6 +14,12 @@ AllCops: Style/AndOr: Enabled: true +# Do not use braces for hash literals when they are the last argument of a +# method call. +Style/BracesAroundHashParameters: + Enabled: true + EnforcedStyle: context_dependent + # Align `when` with `case`. Layout/CaseIndentation: Enabled: true @@ -40,7 +46,7 @@ Layout/EmptyLinesAroundMethodBody: Layout/EmptyLinesAroundModuleBody: Enabled: true -Layout/FirstArgumentIndentation: +Layout/IndentFirstArgument: Enabled: true # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. @@ -51,7 +57,7 @@ Style/HashSyntax: # extra level of indentation. Layout/IndentationConsistency: Enabled: true - EnforcedStyle: indented_internal_methods + EnforcedStyle: rails # Two spaces, no tabs (for indentation). Layout/IndentationWidth: @@ -117,7 +123,7 @@ Layout/Tab: Enabled: true # Blank lines should not have any spaces. -Layout/TrailingEmptyLines: +Layout/TrailingBlankLines: Enabled: true # No trailing whitespace. @@ -125,7 +131,7 @@ Layout/TrailingWhitespace: Enabled: false # Use quotes for string literals when they are enough. -Style/RedundantPercentQ: +Style/UnneededPercentQ: Enabled: true # Align `end` with the matching keyword or starting expression except for From 4f9c85491c3308d57c25dad700f5b636485c8ca8 Mon Sep 17 00:00:00 2001 From: Rhuan <283004+rhuanbarreto@users.noreply.github.com> Date: Thu, 28 May 2020 03:33:06 +0200 Subject: [PATCH 56/86] Fix ruby deprecation error (#6450) * Update obsolete config in rubocop. * Update generated petstore clients --- rubocop.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.mustache b/rubocop.mustache index df46058490d0..d32b2b1cdab5 100644 --- a/rubocop.mustache +++ b/rubocop.mustache @@ -113,7 +113,7 @@ Layout/SpaceInsideParens: # EnforcedStyle: single_quotes # Detect hard tabs, no hard tabs. -Layout/Tab: +Layout/IndentationStyle: Enabled: true # Blank lines should not have any spaces. From e1b96a6e3135395eb981250592f90847ebcba206 Mon Sep 17 00:00:00 2001 From: Julien Feltesse Date: Wed, 10 Jun 2020 18:20:16 +0900 Subject: [PATCH 57/86] remove the json dependency (#6580) --- gemspec.mustache | 1 - 1 file changed, 1 deletion(-) diff --git a/gemspec.mustache b/gemspec.mustache index 0fe63c2e47bc..06334b127cb7 100644 --- a/gemspec.mustache +++ b/gemspec.mustache @@ -30,7 +30,6 @@ Gem::Specification.new do |s| {{^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' From 427abb75fb3a4b597808a54e1dfcd36e5aebac96 Mon Sep 17 00:00:00 2001 From: Tomohiro Suwa Date: Fri, 17 Jul 2020 00:39:21 +0900 Subject: [PATCH 58/86] [Ruby] ruby client build from hash nullable (#6945) * Ruby Client: nullable for build_from_hash * Generate sameples with a8eed9ce38e --- base_object.mustache | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base_object.mustache b/base_object.mustache index cf4a62a99eb2..f6ebfff37915 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -22,7 +22,9 @@ end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) - end # or else data not found in attributes(hash), not an issue as the data can be optional + elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + end end self From e5609a98d3541a40c4b1055da36f5b028815e5b6 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 15 Sep 2020 21:25:52 +0800 Subject: [PATCH 59/86] rename debugging variables (#7422) --- api.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.mustache b/api.mustache index bebf2fcae866..74ec66871dbb 100644 --- a/api.mustache +++ b/api.mustache @@ -173,13 +173,13 @@ module {{moduleName}} {{/formParams}} # http body (model) - post_body = opts[:body] {{#bodyParam}}|| @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) {{/bodyParam}} + post_body = opts[:debug_body]{{#bodyParam}} || @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}){{/bodyParam}} # return_type - return_type = opts[:return_type] {{#returnType}}|| '{{{returnType}}}' {{/returnType}} + return_type = opts[:debug_return_type]{{#returnType}} || '{{{returnType}}}'{{/returnType}} # auth_names - auth_names = opts[:auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] + auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] new_options = opts.merge( :header_params => header_params, From 4ddb64e0e619b75f153f06a97eaa635f5ec5a4a8 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 21 Sep 2020 13:23:45 +0800 Subject: [PATCH 60/86] [Ruby] fix port in the Ruby client (#7464) * fix port in ruby client * use serverPort instead * update samples, skip if port is 80 --- configuration.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration.mustache b/configuration.mustache index 5e2f57980c4b..ba9eda72eefb 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -90,7 +90,7 @@ module {{moduleName}} def initialize @scheme = '{{scheme}}' - @host = '{{host}}' + @host = '{{host}}{{#port}}:{{{.}}}{{/port}}' @base_path = '{{contextPath}}' @api_key = {} @api_key_prefix = {} From 8857eff22d3319ca4a0e7021ac95928f71010e34 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Thu, 24 Sep 2020 17:21:43 +0200 Subject: [PATCH 61/86] [ruby] Support for per-operation servers (#7415) * Support server configuration per operation * regenerated+tests * base_url fix * support not templated urls * revert update of ruby docs --- api.mustache | 1 + api_client.mustache | 4 +- api_client_faraday_partial.mustache | 2 +- api_client_typhoeus_partial.mustache | 2 +- configuration.mustache | 78 ++++++++++++++++++++++++++-- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/api.mustache b/api.mustache index 74ec66871dbb..80f706f23f43 100644 --- a/api.mustache +++ b/api.mustache @@ -182,6 +182,7 @@ module {{moduleName}} auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] new_options = opts.merge( + :operation => :"{{classname}}.{{operationId}}", :header_params => header_params, :query_params => query_params, :form_params => form_params, diff --git a/api_client.mustache b/api_client.mustache index f3139eaa46eb..ae276c93ea0f 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -177,10 +177,10 @@ module {{moduleName}} filename.gsub(/.*[\/\\]/, '') end - def build_request_url(path) + def build_request_url(path, opts = {}) # Add leading and trailing slashes to path path = "/#{path}".gsub(/\/+/, '/') - @config.base_url + path + @config.base_url(opts[:operation]) + path end # Update hearder and query params based on authentication settings. diff --git a/api_client_faraday_partial.mustache b/api_client_faraday_partial.mustache index fec52da71b2f..9675d997c9de 100644 --- a/api_client_faraday_partial.mustache +++ b/api_client_faraday_partial.mustache @@ -63,7 +63,7 @@ # @option opts [Object] :body HTTP body (JSON/XML) # @return [Typhoeus::Request] A Typhoeus Request def build_request(http_method, path, request, opts = {}) - url = build_request_url(path) + url = build_request_url(path, opts) http_method = http_method.to_sym.downcase header_params = @default_headers.merge(opts[:header_params] || {}) diff --git a/api_client_typhoeus_partial.mustache b/api_client_typhoeus_partial.mustache index bd554afc0066..140f7f9a9bcf 100644 --- a/api_client_typhoeus_partial.mustache +++ b/api_client_typhoeus_partial.mustache @@ -43,7 +43,7 @@ # @option opts [Object] :body HTTP body (JSON/XML) # @return [Typhoeus::Request] A Typhoeus Request def build_request(http_method, path, opts = {}) - url = build_request_url(path) + url = build_request_url(path, opts) http_method = http_method.to_sym.downcase header_params = @default_headers.merge(opts[:header_params] || {}) diff --git a/configuration.mustache b/configuration.mustache index ba9eda72eefb..fd1ad422ddb1 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -13,6 +13,18 @@ module {{moduleName}} # Defines url base path attr_accessor :base_path + # Define server configuration index + attr_accessor :server_index + + # Define server operation configuration index + attr_accessor :server_operation_index + + # Default server variables + attr_accessor :server_variables + + # Default server operation variables + attr_accessor :server_operation_variables + # Defines API keys used with API Key authentications. # # @return [Hash] key: parameter name, value: parameter value (API key) @@ -92,6 +104,10 @@ module {{moduleName}} @scheme = '{{scheme}}' @host = '{{host}}{{#port}}:{{{.}}}{{/port}}' @base_path = '{{contextPath}}' + @server_index = 0 + @server_operation_index = {} + @server_variables = {} + @server_operation_variables = {} @api_key = {} @api_key_prefix = {} @timeout = 0 @@ -143,8 +159,12 @@ module {{moduleName}} @base_path = '' if @base_path == '/' end - def base_url - "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') + # Returns base URL for specified operation based on server settings + def base_url(operation = nil) + index = server_operation_index.fetch(operation, server_index) + return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil + + server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation]) end # Gets API key (with prefix if set). @@ -244,12 +264,58 @@ module {{moduleName}} ] end + def operation_server_settings + { + {{#apiInfo}} + {{#apis}} + {{#operations}} + {{#operation}} + {{#servers}} + {{#-first}} + "{{{classname}}}.{{{nickname}}}": [ + {{/-first}} + { + url: "{{{url}}}", + description: "{{{description}}}{{^description}}No description provided{{/description}}", + {{#variables}} + {{#-first}} + variables: { + {{/-first}} + {{{name}}}: { + description: "{{{description}}}{{^description}}No description provided{{/description}}", + default_value: "{{{defaultValue}}}", + {{#enumValues}} + {{#-first}} + enum_values: [ + {{/-first}} + "{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ] + {{/-last}} + {{/enumValues}} + }{{^-last}},{{/-last}} + {{#-last}} + } + {{/-last}} + {{/variables}} + }{{^-last}},{{/-last}} + {{#-last}} + ], + {{/-last}} + {{/servers}} + {{/operation}} + {{/operations}} + {{/apis}} + {{/apiInfo}} + } + end + # Returns URL based on server settings # # @param index array index of the server settings # @param variables hash of variable and the corresponding value - def server_url(index, variables = {}) - servers = server_settings + def server_url(index, variables = {}, servers = nil) + servers = server_settings if servers == nil # check array index out of bound if (index < 0 || index >= servers.size) @@ -259,10 +325,12 @@ module {{moduleName}} server = servers[index] url = server[:url] + return url unless server.key? :variables + # go through variable and assign a value server[:variables].each do |name, variable| if variables.key?(name) - if (server[:variables][name][:enum_values].include? variables[name]) + if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])) url.gsub! "{" + name.to_s + "}", variables[name] else fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." From 87f049b6f62654597e739eda927761ea3ee1f41c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 2 Oct 2020 18:46:49 +0800 Subject: [PATCH 62/86] update default faraday versions (#7538) --- gemspec.mustache | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/gemspec.mustache b/gemspec.mustache index 06334b127cb7..ea84291d48c4 100644 --- a/gemspec.mustache +++ b/gemspec.mustache @@ -16,16 +16,11 @@ Gem::Specification.new do |s| s.homepage = "{{gemHomepage}}{{^gemHomepage}}https://openapi-generator.tech{{/gemHomepage}}" s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" - {{#gemLicense}} - s.license = '{{{gemLicense}}}' - {{/gemLicense}} - {{^gemLicense}} - s.license = "Unlicense" - {{/gemLicense}} - s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 1.9{{/gemRequiredRubyVersion}}" + s.license = "{{{gemLicense}}}{{^gemLicense}}Unlicense{{/gemLicense}}" + s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 2.4{{/gemRequiredRubyVersion}}" {{#isFaraday}} - s.add_runtime_dependency 'faraday', '>= 0.14.0' + s.add_runtime_dependency 'faraday', '~> 1.0', '>= 1.0.1' {{/isFaraday}} {{^isFaraday}} s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' From 1ee4adde5e618004a00c00c9eb4d80699181e55c Mon Sep 17 00:00:00 2001 From: Tomohiro Suwa Date: Wed, 7 Oct 2020 02:14:56 +0900 Subject: [PATCH 63/86] [Ruby] Feature/ruby client build from hash nullable array (#7609) * Ruby Client: nullable build_from_hash for array type * Genearte samples with 8217ecaeb --- base_object.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base_object.mustache b/base_object.mustache index f6ebfff37915..a109dd19f0a1 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -14,7 +14,9 @@ super(attributes) {{/parent}} self.class.openapi_types.each_pair do |key, type| - if type =~ /\AArray<(.*)>/i + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) @@ -22,8 +24,6 @@ end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) - elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) - self.send("#{key}=", nil) end end From ba7b6394910a11753b0664de4c80e69fedfe9b41 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 12 Oct 2020 09:12:37 -0700 Subject: [PATCH 64/86] Unifies naming for isMap in Schema class properties (#7640) * Updates isMapModel + isMapContainer -> isMap * Removes git conflict characters --- partial_model_generic.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 536d8f2926be..6cb3892ea3b6 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -137,11 +137,11 @@ self.{{{name}}} = value end {{/isListContainer}} - {{#isMapContainer}} + {{#isMap}} if (value = attributes[:'{{{name}}}']).is_a?(Hash) self.{{{name}}} = value end - {{/isMapContainer}} + {{/isMap}} {{^isContainer}} self.{{{name}}} = attributes[:'{{{name}}}'] {{/isContainer}} From 9f84472964cafd186e46339b367fcfc208619bea Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 18 Oct 2020 21:58:59 -0700 Subject: [PATCH 65/86] Unifies naming for isArray in Schema class properties (#7691) * Updates key java files * Adds all lingering isArray fixes * Adds two files * Reverts two cs files * Fixes lingering isListContainer + isArrayModel references * Some ensure up to date updates --- partial_model_generic.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 6cb3892ea3b6..e5e491913e53 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -132,11 +132,11 @@ {{#vars}} if attributes.key?(:'{{{name}}}') - {{#isListContainer}} + {{#isArray}} if (value = attributes[:'{{{name}}}']).is_a?(Array) self.{{{name}}} = value end - {{/isListContainer}} + {{/isArray}} {{#isMap}} if (value = attributes[:'{{{name}}}']).is_a?(Hash) self.{{{name}}} = value From a962346d87806f0c55d2f2bb29a2041803edbcb1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 21 Oct 2020 14:13:59 +0800 Subject: [PATCH 66/86] [Ruby] Replace DateTime with Time (#7656) * replace DateTime with Time * add require time * update doc --- api_client.mustache | 7 ++++--- base_object.mustache | 6 +++--- model.mustache | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index ae276c93ea0f..7449326209c6 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -6,6 +6,7 @@ require 'date' require 'json' require 'logger' require 'tempfile' +require 'time' {{^isFaraday}} require 'typhoeus' {{/isFaraday}} @@ -80,7 +81,7 @@ module {{moduleName}} begin data = JSON.parse("[#{body}]", :symbolize_names => true)[0] rescue JSON::ParserError => e - if %w(String Date DateTime).include?(return_type) + if %w(String Date Time).include?(return_type) data = body else raise e @@ -105,9 +106,9 @@ module {{moduleName}} data.to_f when 'Boolean' data == true - when 'DateTime' + when 'Time' # parse date time (expecting ISO 8601 format) - DateTime.parse data + Time.parse data when 'Date' # parse date time (expecting ISO 8601 format) Date.parse data diff --git a/base_object.mustache b/base_object.mustache index a109dd19f0a1..abda94a7eb1d 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -36,8 +36,8 @@ # @return [Object] Deserialized data def _deserialize(type, value) case type.to_sym - when :DateTime - DateTime.parse(value) + when :Time + Time.parse(value) when :Date Date.parse(value) when :String @@ -115,4 +115,4 @@ else value end - end \ No newline at end of file + end diff --git a/model.mustache b/model.mustache index 04eb79cd53e0..345d502b1d49 100644 --- a/model.mustache +++ b/model.mustache @@ -3,6 +3,7 @@ =end require 'date' +require 'time' module {{moduleName}} {{#models}} From 81a64889a32955ddf56acf50a0876b29cc8a934b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 26 Oct 2020 10:07:45 +0800 Subject: [PATCH 67/86] [Ruby][faraday] fix response streaming (#7734) * test file return * fix stream response * use options * use local var * fix nil tempfile * fix tempfile * fix tempfile * use stream * check content * open temp file * test ruby file download * fix stream data * test faraday * catch connection error * catch Faraday::ConnectionFailed * catch all error * use sream * refactor * fi download file in faraday * local fix * fi streaming download * undo changess to spec, test * undo changes to spec --- api_client.mustache | 51 +++++++--------------------- api_client_faraday_partial.mustache | 38 +++++++++++++++++++++ api_client_typhoeus_partial.mustache | 38 +++++++++++++++++++++ 3 files changed, 89 insertions(+), 38 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index 7449326209c6..fd043cd31f90 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -66,7 +66,20 @@ module {{moduleName}} # handle file downloading - return the File instance processed in request callbacks # note that response body is empty when the file is written in chunks in request on_body callback + {{^isFaraday}} return @tempfile if return_type == 'File' + {{/isFaraday}} + {{#isFaraday}} + if return_type == 'File' + @tempfile.write(@stream) + @tempfile.close + @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + return @tempfile + end + {{/isFaraday}} return nil if body.nil? || body.empty? @@ -131,44 +144,6 @@ module {{moduleName}} end end - # Save response body into a file in (the defined) temporary folder, using the filename - # from the "Content-Disposition" header if provided, otherwise a random filename. - # The response body is written to the file in chunks in order to handle files which - # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby - # process can use. - # - # @see Configuration#temp_folder_path - def download_file(request) - tempfile = nil - encoding = nil - request.on_headers do |response| - content_disposition = response.headers['Content-Disposition'] - if content_disposition && content_disposition =~ /filename=/i - filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] - prefix = sanitize_filename(filename) - else - prefix = 'download-' - end - prefix = prefix + '-' unless prefix.end_with?('-') - encoding = response.body.encoding - tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) - @tempfile = tempfile - end - request.on_body do |chunk| - chunk.force_encoding(encoding) - tempfile.write(chunk) - end - request.on_complete do |response| - if tempfile - tempfile.close - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" - end - end - end - # Sanitize filename by removing path. # e.g. ../../sun.gif becomes sun.gif # diff --git a/api_client_faraday_partial.mustache b/api_client_faraday_partial.mustache index 9675d997c9de..e4fce575857b 100644 --- a/api_client_faraday_partial.mustache +++ b/api_client_faraday_partial.mustache @@ -127,3 +127,41 @@ end data end + + # Save response body into a file in (the defined) temporary folder, using the filename + # from the "Content-Disposition" header if provided, otherwise a random filename. + # The response body is written to the file in chunks in order to handle files which + # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby + # process can use. + # + # @see Configuration#temp_folder_path + def download_file(request) + tempfile = nil + encoding = nil + request.headers do |response| + content_disposition = response.headers['Content-Disposition'] + if content_disposition && content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = response.body.encoding + tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile = tempfile + end + + if tempfile.nil? + tempfile = Tempfile.open('download-', @config.temp_folder_path) + @tempfile = tempfile + end + + @stream = [] + + # handle streaming Responses + request.options.on_data = Proc.new do |chunk, overall_received_bytes| + @stream << chunk + end + + end diff --git a/api_client_typhoeus_partial.mustache b/api_client_typhoeus_partial.mustache index 140f7f9a9bcf..e0c9e7cc1d65 100644 --- a/api_client_typhoeus_partial.mustache +++ b/api_client_typhoeus_partial.mustache @@ -113,3 +113,41 @@ end data end + + # Save response body into a file in (the defined) temporary folder, using the filename + # from the "Content-Disposition" header if provided, otherwise a random filename. + # The response body is written to the file in chunks in order to handle files which + # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby + # process can use. + # + # @see Configuration#temp_folder_path + def download_file(request) + tempfile = nil + encoding = nil + request.on_headers do |response| + content_disposition = response.headers['Content-Disposition'] + if content_disposition && content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = response.body.encoding + tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile = tempfile + end + request.on_body do |chunk| + chunk.force_encoding(encoding) + tempfile.write(chunk) + end + request.on_complete do |response| + if tempfile + tempfile.close + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" + end + end + end From 7f0b5a14b3af09a78f41d1c5773648bd5f1aad8f Mon Sep 17 00:00:00 2001 From: Tomohiro Suwa Date: Sat, 31 Oct 2020 17:20:31 +0900 Subject: [PATCH 68/86] [Ruby][faraday] fix download_file (#7842) * Fix download_file * Generate samples with f1df6acdee6 * fixup! Fix download_file * Generate samples with 3e3ea88b0dec7763c8 --- api_client.mustache | 12 +++++++++++- api_client_faraday_partial.mustache | 29 ----------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index fd043cd31f90..3400b97da4ec 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -71,7 +71,17 @@ module {{moduleName}} {{/isFaraday}} {{#isFaraday}} if return_type == 'File' - @tempfile.write(@stream) + content_disposition = response.headers['Content-Disposition'] + if content_disposition && content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = body.encoding + @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile.write(@stream.join.force_encoding(encoding)) @tempfile.close @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ diff --git a/api_client_faraday_partial.mustache b/api_client_faraday_partial.mustache index e4fce575857b..96e1e1142ad7 100644 --- a/api_client_faraday_partial.mustache +++ b/api_client_faraday_partial.mustache @@ -128,40 +128,11 @@ data end - # Save response body into a file in (the defined) temporary folder, using the filename - # from the "Content-Disposition" header if provided, otherwise a random filename. - # The response body is written to the file in chunks in order to handle files which - # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby - # process can use. - # - # @see Configuration#temp_folder_path def download_file(request) - tempfile = nil - encoding = nil - request.headers do |response| - content_disposition = response.headers['Content-Disposition'] - if content_disposition && content_disposition =~ /filename=/i - filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] - prefix = sanitize_filename(filename) - else - prefix = 'download-' - end - prefix = prefix + '-' unless prefix.end_with?('-') - encoding = response.body.encoding - tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) - @tempfile = tempfile - end - - if tempfile.nil? - tempfile = Tempfile.open('download-', @config.temp_folder_path) - @tempfile = tempfile - end - @stream = [] # handle streaming Responses request.options.on_data = Proc.new do |chunk, overall_received_bytes| @stream << chunk end - end From e6624c502d96e4074720a05bcfa3281960f89906 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 6 Nov 2020 19:04:12 -0800 Subject: [PATCH 69/86] Removes secondaryParam and hasMore (#7882) * Removes secondaryParam and hasMore * Fixes tests * Only uses bodyParam in groovy template --- api.mustache | 6 +++--- api_doc.mustache | 4 ++-- partial_model_generic.mustache | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api.mustache b/api.mustache index 80f706f23f43..b99c918b9205 100644 --- a/api.mustache +++ b/api.mustache @@ -142,11 +142,11 @@ module {{moduleName}} header_params = opts[:header_params] || {} {{#hasProduces}} # HTTP header 'Accept' (if needed) - header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) + header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) {{/hasProduces}} {{#hasConsumes}} # HTTP header 'Content-Type' - header_params['Content-Type'] = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]) + header_params['Content-Type'] = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]) {{/hasConsumes}} {{#headerParams}} {{#required}} @@ -179,7 +179,7 @@ module {{moduleName}} return_type = opts[:debug_return_type]{{#returnType}} || '{{{returnType}}}'{{/returnType}} # auth_names - auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] + auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] new_options = opts.merge( :operation => :"{{classname}}.{{operationId}}", diff --git a/api_doc.mustache b/api_doc.mustache index 0e5d35513e32..323e429bcd29 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -83,8 +83,8 @@ Name | Type | Description | Notes ### HTTP request headers -- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} -- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} +- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} +- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}} {{/operation}} {{/operations}} diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index e5e491913e53..7d68ab36e9c0 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -37,7 +37,7 @@ def self.attribute_map { {{#vars}} - :'{{{name}}}' => :'{{{baseName}}}'{{#hasMore}},{{/hasMore}} + :'{{{name}}}' => :'{{{baseName}}}'{{^-last}},{{/-last}} {{/vars}} } end @@ -46,7 +46,7 @@ def self.openapi_types { {{#vars}} - :'{{{name}}}' => :'{{{dataType}}}'{{#hasMore}},{{/hasMore}} + :'{{{name}}}' => :'{{{dataType}}}'{{^-last}},{{/-last}} {{/vars}} } end @@ -56,7 +56,7 @@ Set.new([ {{#vars}} {{#isNullable}} - :'{{{name}}}'{{#hasMore}},{{/hasMore}} + :'{{{name}}}'{{^-last}},{{/-last}} {{/isNullable}} {{/vars}} ]) @@ -387,7 +387,7 @@ # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [{{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}].hash + [{{#vars}}{{name}}{{^-last}}, {{/-last}}{{/vars}}].hash end {{> base_object}} From a57f3679bb23c9d4ca80e5b71e04716710535c74 Mon Sep 17 00:00:00 2001 From: Julien Feltesse Date: Mon, 23 Nov 2020 23:43:34 +0900 Subject: [PATCH 70/86] [ruby] fix oneOf handling (#5706) * [ruby] fix oneOf handling * use previous ruby configs due to issue #4690 * check for oneOf model in base_object * validate the attributes in partial_oneof_module --- api_client.mustache | 5 +- api_doc.mustache | 24 +++-- base_object.mustache | 6 +- model.mustache | 7 ++ model_doc.mustache | 31 +++---- model_test.mustache | 52 ++++++++--- partial_model_generic.mustache | 45 +++------- partial_model_generic_doc.mustache | 28 ++++++ partial_oneof_module.mustache | 137 +++++++++++++++++++++++++++++ partial_oneof_module_doc.mustache | 92 +++++++++++++++++++ 10 files changed, 351 insertions(+), 76 deletions(-) create mode 100644 partial_model_generic_doc.mustache create mode 100644 partial_oneof_module.mustache create mode 100644 partial_oneof_module_doc.mustache diff --git a/api_client.mustache b/api_client.mustache index 3400b97da4ec..6723bb756c66 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -149,8 +149,9 @@ module {{moduleName}} data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } end else - # models, e.g. Pet - {{moduleName}}.const_get(return_type).build_from_hash(data) + # models (e.g. Pet) or oneOf + klass = {{moduleName}}.const_get(return_type) + klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data) end end diff --git a/api_doc.mustache b/api_doc.mustache index 323e429bcd29..f9b9f78f8707 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -4,10 +4,13 @@ All URIs are relative to *{{basePath}}* -Method | HTTP request | Description -------------- | ------------- | ------------- -{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} -{{/operation}}{{/operations}} +| Method | HTTP request | Description | +| ------ | ------------ | ----------- | +{{#operations}} +{{#operation}} +| [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} | +{{/operation}} +{{/operations}} {{#operations}} {{#operation}} @@ -67,10 +70,15 @@ end ### Parameters -{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} -Name | Type | Description | Notes -------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} -{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{^allParams}} +This endpoint does not need any parameter. +{{/allParams}} +{{#allParams}} +{{#-first}} +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +{{/-first}} +| **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} | {{/allParams}} ### Return type diff --git a/base_object.mustache b/base_object.mustache index abda94a7eb1d..00a8e35b88f7 100644 --- a/base_object.mustache +++ b/base_object.mustache @@ -67,7 +67,9 @@ end end else # model - {{moduleName}}.const_get(type).build_from_hash(value) + # models (e.g. Pet) or oneOf + klass = {{moduleName}}.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) end end @@ -93,7 +95,7 @@ is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end - + hash[param] = _to_hash(value) end hash diff --git a/model.mustache b/model.mustache index 345d502b1d49..fa8f8c5bbb17 100644 --- a/model.mustache +++ b/model.mustache @@ -12,7 +12,14 @@ module {{moduleName}} {{>partial_model_enum_class}} {{/isEnum}} {{^isEnum}} +{{#oneOf}} +{{#-first}} +{{>partial_oneof_module}} +{{/-first}} +{{/oneOf}} +{{^oneOf}} {{>partial_model_generic}} +{{/oneOf}} {{/isEnum}} {{/model}} {{/models}} diff --git a/model_doc.mustache b/model_doc.mustache index c2a790d9dace..37809685d1c0 100644 --- a/model_doc.mustache +++ b/model_doc.mustache @@ -1,19 +1,12 @@ -{{#models}}{{#model}}# {{moduleName}}::{{classname}} - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} -{{/vars}} - -## Code Sample - -```ruby -require '{{moduleName}}' - -instance = {{moduleName}}::{{classname}}.new({{#vars}}{{name}}: {{example}}{{^-last}}, - {{/-last}}{{/vars}}) -``` - -{{/model}}{{/models}} +{{#models}} +{{#model}} +{{#oneOf}} +{{#-first}} +{{>partial_oneof_module_doc}} +{{/-first}} +{{/oneOf}} +{{^oneOf}} +{{>partial_model_generic_doc}} +{{/oneOf}} +{{/model}} +{{/models}} diff --git a/model_test.mustache b/model_test.mustache index 47b8d53c3197..47bd571592e9 100644 --- a/model_test.mustache +++ b/model_test.mustache @@ -11,19 +11,13 @@ require 'date' # Please update as you see appropriate {{#models}} {{#model}} -describe '{{classname}}' do - before do - # run before each test - @instance = {{moduleName}}::{{classname}}.new - end - - after do - # run after each test - end +describe {{moduleName}}::{{classname}} do +{{^oneOf}} + let(:instance) { {{moduleName}}::{{classname}}.new } describe 'test an instance of {{classname}}' do it 'should create an instance of {{classname}}' do - expect(@instance).to be_instance_of({{moduleName}}::{{classname}}) + expect(instance).to be_instance_of({{moduleName}}::{{classname}}) end end {{#vars}} @@ -33,7 +27,7 @@ describe '{{classname}}' do # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]) # validator.allowable_values.each do |value| - # expect { @instance.{{name}} = value }.not_to raise_error + # expect { instance.{{name}} = value }.not_to raise_error # end {{/isEnum}} {{^isEnum}} @@ -43,6 +37,42 @@ describe '{{classname}}' do end {{/vars}} +{{/oneOf}} +{{#oneOf}} +{{#-first}} + describe '.openapi_one_of' do + it 'lists the models referenced in the oneOf array' do + expect(described_class.openapi_one_of).to_not be_empty + described_class.openapi_one_of.each { |klass| expect { {{moduleName}}.const_get(klass) }.to_not raise_error } + end + end + + {{#discriminator}} + {{#propertyName}} + describe '.openapi_discriminator_name' do + it 'returns the value of the "discriminator" property' do + expect(described_class.openapi_discriminator_name).to_not be_empty + end + end + + {{/propertyName}} + {{#mappedModels}} + {{#-first}} + describe '.openapi_discriminator_mapping' do + it 'returns the key/values of the "mapping" property' do + expect(described_class.openapi_discriminator_mapping.values.sort).to eq(described_class.openapi_one_of.sort) + end + end + + {{/-first}} + {{/mappedModels}} + {{/discriminator}} + describe '.build' do + it 'returns the correct model' do + end + end +{{/-first}} +{{/oneOf}} end {{/model}} {{/models}} diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 7d68ab36e9c0..9963d883d6c7 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -42,6 +42,16 @@ } end + # Returns all the JSON keys this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}} + def self.acceptable_attributes + {{^parent}} + attribute_map.values + {{/parent}} + {{#parent}} + attribute_map.values.concat(superclass.acceptable_attributes) + {{/parent}} + end + # Attribute type mapping. def self.openapi_types { @@ -75,19 +85,6 @@ {{/-last}} {{/anyOf}} - {{#oneOf}} - {{#-first}} - # List of class defined in oneOf (OpenAPI v3) - def self.openapi_one_of - [ - {{/-first}} - :'{{{.}}}'{{^-last}},{{/-last}} - {{#-last}} - ] - end - - {{/-last}} - {{/oneOf}} {{#allOf}} {{#-first}} # List of class defined in allOf (OpenAPI v3) @@ -270,26 +267,6 @@ {{/-first}} {{/anyOf}} - {{#oneOf}} - {{#-first}} - _one_of_found = false - self.class.openapi_one_of.each do |_class| - _one_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash) - if _one_of.valid? - if _one_of_found - return false - else - _one_of_found = true - end - end - end - - if !_one_of_found - return false - end - - {{/-first}} - {{/oneOf}} true{{#parent}} && super{{/parent}} end @@ -391,4 +368,4 @@ end {{> base_object}} - end \ No newline at end of file + end diff --git a/partial_model_generic_doc.mustache b/partial_model_generic_doc.mustache new file mode 100644 index 000000000000..72778dff1e61 --- /dev/null +++ b/partial_model_generic_doc.mustache @@ -0,0 +1,28 @@ +# {{moduleName}}::{{classname}} + +## Properties + +| Name | Type | Description | Notes | +| ---- | ---- | ----------- | ----- | +{{#vars}} +| **{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#isReadOnly}}[readonly]{{/isReadOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} | +{{/vars}} + +## Code Sample + +```ruby +require '{{{gemName}}}' + +{{^vars}} +instance = {{moduleName}}::{{classname}}.new() +{{/vars}} +{{#vars}} +{{#-first}} +instance = {{moduleName}}::{{classname}}.new( +{{/-first}} + {{name}}: {{example}}{{^-last}},{{/-last}} +{{#-last}} +) +{{/-last}} +{{/vars}} +``` diff --git a/partial_oneof_module.mustache b/partial_oneof_module.mustache new file mode 100644 index 000000000000..14dc1635bb74 --- /dev/null +++ b/partial_oneof_module.mustache @@ -0,0 +1,137 @@ + {{#description}} + # {{{description}}} + {{/description}} + module {{classname}} + class << self + {{#oneOf}} + {{#-first}} + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/oneOf}} + {{#discriminator}} + {{#propertyName}} + # Discriminator's property name (OpenAPI v3) + def openapi_discriminator_name + :'{{{.}}}' + end + + {{/propertyName}} + {{#mappedModels}} + {{#-first}} + # Discriminator's mapping (OpenAPI v3) + def openapi_discriminator_mapping + { + {{/-first}} + :'{{{mappingName}}}' => :'{{{modelName}}}'{{^-last}},{{/-last}} + {{#-last}} + } + end + + {{/-last}} + {{/mappedModels}} + {{/discriminator}} + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + {{#discriminator}} + discriminator_value = data[openapi_discriminator_name] + return nil unless discriminator_value + {{#mappedModels}} + {{#-first}} + + klass = openapi_discriminator_mapping[discriminator_value.to_sym] + return nil unless klass + + {{moduleName}}.const_get(klass).build_from_hash(data) + {{/-first}} + {{/mappedModels}} + {{^mappedModels}} + {{moduleName}}.const_get(discriminator_value).build_from_hash(data) + {{/mappedModels}} + {{/discriminator}} + {{^discriminator}} + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are defacto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + {{/discriminator}} + end + {{^discriminator}} + + private + + SchemaMismatchError = Class.new(StandardError) + + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when 'Boolean' + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when 'Float' + return data if data.instance_of?(Float) + when 'Integer' + return data if data.instance_of?(Integer) + when 'Time' + return Time.parse(data) + when 'Date' + return Date.parse(data) + when 'String' + return data if data.instance_of?(String) + when 'Object' # "type: object" + return data if data.instance_of?(Hash) + when /\AArray<(?.+)>\z/ # "type: array" + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + when /\AHash.+)>\z/ # "type: object" with "additionalProperties: { ... }" + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + else # model + const = {{moduleName}}.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) # nested oneOf model + model = const.build(data) + return model if model + else + # raise if data contains keys that are not known to the model + raise unless (data.keys - const.acceptable_attributes).empty? + model = const.build_from_hash(data) + return model if model && model.valid? + end + end + end + + raise # if no match by now, raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + {{/discriminator}} + end + end diff --git a/partial_oneof_module_doc.mustache b/partial_oneof_module_doc.mustache new file mode 100644 index 000000000000..64a6c32dc854 --- /dev/null +++ b/partial_oneof_module_doc.mustache @@ -0,0 +1,92 @@ +# {{moduleName}}::{{classname}} + +## Class instance methods + +### `openapi_one_of` + +Returns the list of classes defined in oneOf. + +#### Example + +```ruby +require '{{{gemName}}}' + +{{moduleName}}::{{classname}}.openapi_one_of +# => +{{#oneOf}} +{{#-first}} +# [ +{{/-first}} +# :'{{{.}}}'{{^-last}},{{/-last}} +{{#-last}} +# ] +{{/-last}} +{{/oneOf}} +``` +{{#discriminator}} +{{#propertyName}} + +### `openapi_discriminator_name` + +Returns the discriminator's property name. + +#### Example + +```ruby +require '{{{gemName}}}' + +{{moduleName}}::{{classname}}.openapi_discriminator_name +# => :'{{{.}}}' +``` +{{/propertyName}} +{{#mappedModels}} +{{#-first}} + +### `openapi_discriminator_name` + +Returns the discriminator's mapping. + +#### Example + +```ruby +require '{{{gemName}}}' + +{{moduleName}}::{{classname}}.openapi_discriminator_mapping +# => +# { +{{/-first}} +# :'{{{mappingName}}}' => :'{{{modelName}}}'{{^-last}},{{/-last}} +{{#-last}} +# } +{{/-last}} +{{/mappedModels}} +{{/discriminator}} + +### build + +Find the appropriate object from the `openapi_one_of` list and casts the data into it. + +#### Example + +```ruby +require '{{{gemName}}}' + +{{moduleName}}::{{classname}}.build(data) +# => {{#oneOf}}{{#-first}}#<{{{.}}}:0x00007fdd4aab02a0>{{/-first}}{{/oneOf}} + +{{moduleName}}::{{classname}}.build(data_that_doesnt_match) +# => nil +``` + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| **data** | **Mixed** | data to be matched against the list of oneOf items | + +#### Return type + +{{#oneOf}} +- `{{{.}}}` +{{/oneOf}} +- `nil` (if no type matches) From e1aad8b849f5fb7e11e7702bc4882992ac59a3fe Mon Sep 17 00:00:00 2001 From: Julien Feltesse Date: Thu, 26 Nov 2020 00:47:22 +0900 Subject: [PATCH 71/86] make the generated ruby oneOf specs pass (#8019) --- model_test.mustache | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model_test.mustache b/model_test.mustache index 47bd571592e9..86e5438d61ab 100644 --- a/model_test.mustache +++ b/model_test.mustache @@ -41,9 +41,8 @@ describe {{moduleName}}::{{classname}} do {{#oneOf}} {{#-first}} describe '.openapi_one_of' do - it 'lists the models referenced in the oneOf array' do + it 'lists the items referenced in the oneOf array' do expect(described_class.openapi_one_of).to_not be_empty - described_class.openapi_one_of.each { |klass| expect { {{moduleName}}.const_get(klass) }.to_not raise_error } end end From f094c890a84c5a6aefc76b7b7e22776184e5e616 Mon Sep 17 00:00:00 2001 From: Julien Feltesse Date: Sat, 5 Dec 2020 19:27:49 +0900 Subject: [PATCH 72/86] [ruby] document the *_with_http_info methods (#8094) --- api_doc.mustache | 33 +++++++++++++++++++++++------- partial_model_generic_doc.mustache | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/api_doc.mustache b/api_doc.mustache index f9b9f78f8707..e8894a6ea60b 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -17,16 +17,15 @@ All URIs are relative to *{{basePath}}* ## {{operationId}} -> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} +> {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} {{{summary}}}{{#notes}} {{{notes}}}{{/notes}} -### Example +### Examples ```ruby -# load the gem require '{{{gemName}}}' {{#hasAuthMethods}} # setup authorization @@ -60,11 +59,31 @@ opts = { {{/optionalParams}} begin -{{#summary}} #{{{.}}} -{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}{{#returnType}} - p result{{/returnType}} + {{#summary}}# {{{.}}}{{/summary}} + {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} + {{#returnType}} + p result + {{/returnType}} rescue {{{moduleName}}}::ApiError => e - puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}" + puts "Error when calling {{classname}}->{{{operationId}}}: #{e}" +end +``` + +#### Using the {{operationId}}_with_http_info variant + +This returns an Array which contains the response data{{^returnType}} (`nil` in this case){{/returnType}}, status code and headers. + +> {{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Integer, Hash)> {{operationId}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} + +```ruby +begin + {{#summary}}# {{{.}}}{{/summary}} + data, status_code, headers = api_instance.{{{operationId}}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} + p status_code # => 2xx + p headers # => { ... } + p data # => {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}} +rescue {{{moduleName}}}::ApiError => e + puts "Error when calling {{classname}}->{{{operationId}}}_with_http_info: #{e}" end ``` diff --git a/partial_model_generic_doc.mustache b/partial_model_generic_doc.mustache index 72778dff1e61..f188dd23e6ec 100644 --- a/partial_model_generic_doc.mustache +++ b/partial_model_generic_doc.mustache @@ -8,7 +8,7 @@ | **{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#isReadOnly}}[readonly]{{/isReadOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} | {{/vars}} -## Code Sample +## Example ```ruby require '{{{gemName}}}' From 5f4e2db9210cb322de31e674d1f9d3453a0170bb Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 15 Dec 2020 17:10:04 +0100 Subject: [PATCH 73/86] [ruby] Improve ruby client examples (#8040) * [ruby] Improve ruby client examples * samples * quote fixes * Keep enum value * better string type handling * fix failing tests * add space after comment * update samples * use Time Co-authored-by: William Cheng --- README.mustache | 4 ++-- api_doc.mustache | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.mustache b/README.mustache index a527f6ce9d7f..dafacf98ad57 100644 --- a/README.mustache +++ b/README.mustache @@ -82,13 +82,13 @@ require '{{{gemName}}}' api_instance = {{{moduleName}}}::{{{classname}}}.new {{#requiredParams}} -{{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}} +{{{paramName}}} = {{{vendorExtensions.x-ruby-example}}} # {{{dataType}}} | {{{description}}} {{/requiredParams}} {{#optionalParams}} {{#-first}} opts = { {{/-first}} - {{{paramName}}}: {{{example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} + {{{paramName}}}: {{{vendorExtensions.x-ruby-example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} {{#-last}} } {{/-last}} diff --git a/api_doc.mustache b/api_doc.mustache index e8894a6ea60b..bdeeb5689122 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -26,6 +26,7 @@ All URIs are relative to *{{basePath}}* ### Examples ```ruby +require 'time' require '{{{gemName}}}' {{#hasAuthMethods}} # setup authorization @@ -38,7 +39,7 @@ require '{{{gemName}}}' # Configure API key authorization: {{{name}}} 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['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} + # config.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} {{/authMethods}}end @@ -46,13 +47,13 @@ require '{{{gemName}}}' api_instance = {{{moduleName}}}::{{{classname}}}.new {{#requiredParams}} -{{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}} +{{{paramName}}} = {{{vendorExtensions.x-ruby-example}}} # {{{dataType}}} | {{{description}}} {{/requiredParams}} {{#optionalParams}} {{#-first}} opts = { {{/-first}} - {{{paramName}}}: {{{example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} + {{{paramName}}}: {{{vendorExtensions.x-ruby-example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} {{#-last}} } {{/-last}} From 79d6a27b8717a28a52f268ca428e27ea755cb5f0 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 5 Jan 2021 13:04:08 +0100 Subject: [PATCH 74/86] [ruby] Support aliasing of API keys (#8124) * Allow aliasing of auth keys * update sample and add config for feature * update samples Co-authored-by: William Cheng --- README.mustache | 4 ++-- api_client.mustache | 2 +- api_doc.mustache | 4 ++-- configuration.mustache | 10 ++++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.mustache b/README.mustache index dafacf98ad57..e35995e6339b 100644 --- a/README.mustache +++ b/README.mustache @@ -72,9 +72,9 @@ require '{{{gemName}}}' # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} - config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY' + config.api_key['{{{name}}}'] = '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['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} + # config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} {{/authMethods}}end diff --git a/api_client.mustache b/api_client.mustache index 6723bb756c66..2741a73794ed 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -182,7 +182,7 @@ module {{moduleName}} case auth_setting[:in] when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] - else fail ArgumentError, 'Authentication token must be in `query` of `header`' + else fail ArgumentError, 'Authentication token must be in `query` or `header`' end end end diff --git a/api_doc.mustache b/api_doc.mustache index bdeeb5689122..81fc865534d1 100644 --- a/api_doc.mustache +++ b/api_doc.mustache @@ -37,9 +37,9 @@ require '{{{gemName}}}' # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} - config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY' + config.api_key['{{{name}}}'] = '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['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} + # config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} {{/authMethods}}end diff --git a/configuration.mustache b/configuration.mustache index fd1ad422ddb1..26d324489b9d 100644 --- a/configuration.mustache +++ b/configuration.mustache @@ -169,11 +169,13 @@ module {{moduleName}} # Gets API key (with prefix if set). # @param [String] param_name the parameter name of API key auth - def api_key_with_prefix(param_name) + def api_key_with_prefix(param_name, param_alias = nil) + key = @api_key[param_name] + key = @api_key.fetch(param_alias, key) unless param_alias.nil? if @api_key_prefix[param_name] - "#{@api_key_prefix[param_name]} #{@api_key[param_name]}" + "#{@api_key_prefix[param_name]} #{key}" else - @api_key[param_name] + key end end @@ -192,7 +194,7 @@ module {{moduleName}} type: 'api_key', in: {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}, key: '{{keyParamName}}', - value: api_key_with_prefix('{{keyParamName}}') + value: api_key_with_prefix('{{name}}'{{#vendorExtensions.x-auth-id-alias}}, '{{.}}'{{/vendorExtensions.x-auth-id-alias}}) }, {{/isApiKey}} {{#isBasic}} From cb25fb76621aa95aae5a91a9f68458b74b329de7 Mon Sep 17 00:00:00 2001 From: miyucy Date: Fri, 12 Feb 2021 00:43:19 +0900 Subject: [PATCH 75/86] Fix syntax error (#8675) Added missing closing brace in list_invalid_properties model method. --- partial_model_generic.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/partial_model_generic.mustache b/partial_model_generic.mustache index 9963d883d6c7..647963b47457 100644 --- a/partial_model_generic.mustache +++ b/partial_model_generic.mustache @@ -197,13 +197,13 @@ {{/pattern}} {{#maxItems}} if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length > {{{maxItems}}} - invalid_properties.push('invalid value for "{{{name}}}", number of items must be less than or equal to {{{maxItems}}}.' + invalid_properties.push('invalid value for "{{{name}}}", number of items must be less than or equal to {{{maxItems}}}.') end {{/maxItems}} {{#minItems}} if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.length < {{{minItems}}} - invalid_properties.push('invalid value for "{{{name}}}", number of items must be greater than or equal to {{{minItems}}}.' + invalid_properties.push('invalid value for "{{{name}}}", number of items must be greater than or equal to {{{minItems}}}.') end {{/minItems}} From 14ce33367db130a8a67dad429c41fd1932d97719 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 20 Feb 2021 11:49:10 +0800 Subject: [PATCH 76/86] [Ruby] force users to specify the temp folder path to address security concerns (#8730) * address security issue when downloading files in the ruby client * update samples * fix double quote --- api_client.mustache | 7 +++++++ api_client_typhoeus_partial.mustache | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api_client.mustache b/api_client.mustache index 2741a73794ed..7d2cc4a6cb59 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -71,6 +71,13 @@ module {{moduleName}} {{/isFaraday}} {{#isFaraday}} if return_type == 'File' + # throw an exception if the temp folder path is not defined + # to avoid using the default temp directory which can be read by anyone + if @config.temp_folder_path.nil? + raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"]) " + + "to avoid dowloading the file to a location readable by everyone." + end + content_disposition = response.headers['Content-Disposition'] if content_disposition && content_disposition =~ /filename=/i filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] diff --git a/api_client_typhoeus_partial.mustache b/api_client_typhoeus_partial.mustache index e0c9e7cc1d65..496ba6c46fa4 100644 --- a/api_client_typhoeus_partial.mustache +++ b/api_client_typhoeus_partial.mustache @@ -52,8 +52,8 @@ {{#hasAuthMethods}} update_params_for_auth! header_params, query_params, opts[:auth_names] - {{/hasAuthMethods}} + {{/hasAuthMethods}} # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 @@ -122,6 +122,13 @@ # # @see Configuration#temp_folder_path def download_file(request) + # throw an exception if the temp folder path is not defined + # to avoid using the default temp directory which can be read by anyone + if @config.temp_folder_path.nil? + raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" + + "to avoid dowloading the file to a location readable by everyone." + end + tempfile = nil encoding = nil request.on_headers do |response| @@ -137,10 +144,12 @@ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) @tempfile = tempfile end + request.on_body do |chunk| chunk.force_encoding(encoding) tempfile.write(chunk) end + request.on_complete do |response| if tempfile tempfile.close From b6d10d87733f2c5e38d3802ec0f5450ca0c4edc2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 24 Feb 2021 00:31:43 +0800 Subject: [PATCH 77/86] Revert "[Ruby] force users to specify the temp folder path to address security concerns (#8730)" (#8807) This reverts commit 18a6f5a941f3b5777977693f3b59ac5d200928a8. --- api_client.mustache | 7 ------- api_client_typhoeus_partial.mustache | 11 +---------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/api_client.mustache b/api_client.mustache index 7d2cc4a6cb59..2741a73794ed 100644 --- a/api_client.mustache +++ b/api_client.mustache @@ -71,13 +71,6 @@ module {{moduleName}} {{/isFaraday}} {{#isFaraday}} if return_type == 'File' - # throw an exception if the temp folder path is not defined - # to avoid using the default temp directory which can be read by anyone - if @config.temp_folder_path.nil? - raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"]) " + - "to avoid dowloading the file to a location readable by everyone." - end - content_disposition = response.headers['Content-Disposition'] if content_disposition && content_disposition =~ /filename=/i filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] diff --git a/api_client_typhoeus_partial.mustache b/api_client_typhoeus_partial.mustache index 496ba6c46fa4..e0c9e7cc1d65 100644 --- a/api_client_typhoeus_partial.mustache +++ b/api_client_typhoeus_partial.mustache @@ -52,8 +52,8 @@ {{#hasAuthMethods}} update_params_for_auth! header_params, query_params, opts[:auth_names] - {{/hasAuthMethods}} + # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 @@ -122,13 +122,6 @@ # # @see Configuration#temp_folder_path def download_file(request) - # throw an exception if the temp folder path is not defined - # to avoid using the default temp directory which can be read by anyone - if @config.temp_folder_path.nil? - raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" + - "to avoid dowloading the file to a location readable by everyone." - end - tempfile = nil encoding = nil request.on_headers do |response| @@ -144,12 +137,10 @@ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) @tempfile = tempfile end - request.on_body do |chunk| chunk.force_encoding(encoding) tempfile.write(chunk) end - request.on_complete do |response| if tempfile tempfile.close From 0457caf13aa4c7c7f1e3a3bdef18a8ef5fd63761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 78/86] Apply template-patches/ruby-unstable-operations.patch --- .generator/templates/api.mustache | 10 ++++++++++ .generator/templates/configuration.mustache | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/.generator/templates/api.mustache b/.generator/templates/api.mustache index b99c918b9205..5a1ebca1d61b 100644 --- a/.generator/templates/api.mustache +++ b/.generator/templates/api.mustache @@ -39,6 +39,16 @@ module {{moduleName}} {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) + + if @api_client.config.unstable_operations.has_key?(:{{operationId}}) + unstable_enabled = @api_client.config.unstable_operations[:{{operationId}}] + if unstable_enabled + @api_client.config.logger.warn format("Using unstable operation '%s'", "{{operationId}}") + else + raise ApiError.new(message: format("Unstable operation '%s' is disabled", "{{operationId}}")) + end + end + if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' end diff --git a/.generator/templates/configuration.mustache b/.generator/templates/configuration.mustache index 26d324489b9d..9e81074978ca 100644 --- a/.generator/templates/configuration.mustache +++ b/.generator/templates/configuration.mustache @@ -83,6 +83,9 @@ module {{moduleName}} # @return [true, false] attr_accessor :client_side_validation + # Keep track of the unstable operations, and if they have been enabled + attr_accessor :unstable_operations + {{^isFaraday}} {{> configuration_tls_typhoeus_partial}} {{/isFaraday}} @@ -130,6 +133,19 @@ module {{moduleName}} @inject_format = false @force_ending_format = false @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + @unstable_operations = { + {{#apiInfo}} + {{#apis}} + {{#operations}} + {{#operation}} + {{#vendorExtensions.x-unstable}} + {{operationId}}: false, + {{/vendorExtensions.x-unstable}} + {{/operation}} + {{/operations}} + {{/apis}} + {{/apiInfo}} + } yield(self) if block_given? end From 966db377d9ab98186e37ec8e7dc857ff7d197f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 79/86] Apply template-patches/ruby-alias-auth-keys.patch --- .generator/templates/README.mustache | 4 +--- .generator/templates/api_doc.mustache | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.generator/templates/README.mustache b/.generator/templates/README.mustache index e35995e6339b..e54220416054 100644 --- a/.generator/templates/README.mustache +++ b/.generator/templates/README.mustache @@ -72,9 +72,7 @@ require '{{{gemName}}}' # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} - config.api_key['{{{name}}}'] = '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['{{{name}}}'] = ENV["{{{vendorExtensions.x-env-name}}}"]{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} {{/authMethods}}end diff --git a/.generator/templates/api_doc.mustache b/.generator/templates/api_doc.mustache index 81fc865534d1..00fc113a556c 100644 --- a/.generator/templates/api_doc.mustache +++ b/.generator/templates/api_doc.mustache @@ -37,9 +37,7 @@ require '{{{gemName}}}' # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} # Configure API key authorization: {{{name}}} - config.api_key['{{{name}}}'] = '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['{{{name}}}'] = ENV["{{{vendorExtensions.x-env-name}}}"]{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} {{/authMethods}}end From 0dd5a8e51f4affb176f8ebf92b428ab7922d5ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 80/86] Apply template-patches/ruby-license-header.patch --- .generator/templates/api_info.mustache | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.generator/templates/api_info.mustache b/.generator/templates/api_info.mustache index 1b3f9cb5ac45..a9360061c91c 100644 --- a/.generator/templates/api_info.mustache +++ b/.generator/templates/api_info.mustache @@ -9,4 +9,7 @@ {{#version}}The version of the OpenAPI document: {{version}}{{/version}} {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} Generated by: https://openapi-generator.tech -OpenAPI Generator version: {{{generatorVersion}}} + + Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. + This product includes software developed at Datadog (https://www.datadoghq.com/). + Copyright 2020-Present Datadog, Inc. From 96327fd4311a47d4f88744f6f18d405844accfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 81/86] Apply template-patches/ruby-api-docs.patch --- .generator/templates/README.mustache | 4 ++-- .generator/templates/api_doc.mustache | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.generator/templates/README.mustache b/.generator/templates/README.mustache index e54220416054..2a1bd36ca892 100644 --- a/.generator/templates/README.mustache +++ b/.generator/templates/README.mustache @@ -108,12 +108,12 @@ All URIs are relative to *{{basePath}}* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}::{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}::{{classname}}* | [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} ## Documentation for Models -{{#models}}{{#model}} - [{{moduleName}}::{{classname}}]({{modelDocPath}}{{classname}}.md) +{{#models}}{{#model}} - [{{moduleName}}::{{classname}}]({{classname}}.md) {{/model}}{{/models}} ## Documentation for Authorization diff --git a/.generator/templates/api_doc.mustache b/.generator/templates/api_doc.mustache index 00fc113a556c..96d1364cdf63 100644 --- a/.generator/templates/api_doc.mustache +++ b/.generator/templates/api_doc.mustache @@ -96,7 +96,7 @@ This endpoint does not need any parameter. | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | {{/-first}} -| **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} | +| **{{paramName}}** | {{#isContainer}}{{#isArray}}{{#items}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**Array<{{dataType}}>**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isModel}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**Hash<String,{{dataType}}>**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isModel}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**{{dataType}}**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{#baseType}}{{baseType}}{{/baseType}}.md){{/isFile}}{{/isModel}}{{/isContainer}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} | {{/allParams}} ### Return type @@ -105,7 +105,7 @@ This endpoint does not need any parameter. ### Authorization -{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}} +{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}} ### HTTP request headers From 0453b268c4e7de4e81da64d6902fcbf681406af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 82/86] Apply template-patches/ruby-doc-unstable-op.patch --- .generator/templates/api_doc.mustache | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.generator/templates/api_doc.mustache b/.generator/templates/api_doc.mustache index 96d1364cdf63..cae628f1f74d 100644 --- a/.generator/templates/api_doc.mustache +++ b/.generator/templates/api_doc.mustache @@ -40,7 +40,9 @@ require '{{{gemName}}}' config.api_key['{{{name}}}'] = ENV["{{{vendorExtensions.x-env-name}}}"]{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} -{{/authMethods}}end +{{/authMethods}}{{#vendorExtensions.x-unstable}} + config.unstable_operations[:{{{operationId}}}] = true +{{/vendorExtensions.x-unstable}}end {{/hasAuthMethods}} api_instance = {{{moduleName}}}::{{{classname}}}.new From 0fa8793d6e5c1fd358657611f71fc80cf844c066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 83/86] Apply template-patches/ruby-gem-require.patch --- .generator/templates/gem.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.generator/templates/gem.mustache b/.generator/templates/gem.mustache index c9ae0ebf96ea..1bd524764ad1 100644 --- a/.generator/templates/gem.mustache +++ b/.generator/templates/gem.mustache @@ -3,9 +3,9 @@ =end # Common files +require 'datadog_api_client/version' require '{{gemName}}/api_client' require '{{gemName}}/api_error' -require '{{gemName}}/version' require '{{gemName}}/configuration' # Models From 5d73d8a2b91acee1369ab09c0568c00499a3abcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 84/86] Apply template-patches/ruby-examples-with-dd-site.patch --- .generator/templates/api_doc.mustache | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.generator/templates/api_doc.mustache b/.generator/templates/api_doc.mustache index cae628f1f74d..faa292fed7c6 100644 --- a/.generator/templates/api_doc.mustache +++ b/.generator/templates/api_doc.mustache @@ -27,10 +27,14 @@ All URIs are relative to *{{basePath}}* ```ruby require 'time' -require '{{{gemName}}}' +require '{{{gemNameInExamples}}}' + +{{{moduleName}}}.configure do |config| + # Defining the site is optional and defaults to datadoghq.com + config.server_variables['site'] = ENV["DD_SITE"] if ENV.key? 'DD_SITE' {{#hasAuthMethods}} -# setup authorization -{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} + + # setup authorization{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} # Configure HTTP basic authorization: {{{name}}} config.username = 'YOUR USERNAME' config.password = 'YOUR PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}} @@ -40,10 +44,9 @@ require '{{{gemName}}}' config.api_key['{{{name}}}'] = ENV["{{{vendorExtensions.x-env-name}}}"]{{/isApiKey}}{{#isOAuth}} # Configure OAuth2 access token for authorization: {{{name}}} config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}} -{{/authMethods}}{{#vendorExtensions.x-unstable}} +{{/authMethods}}{{/hasAuthMethods}}{{#vendorExtensions.x-unstable}} config.unstable_operations[:{{{operationId}}}] = true {{/vendorExtensions.x-unstable}}end -{{/hasAuthMethods}} api_instance = {{{moduleName}}}::{{{classname}}}.new {{#requiredParams}} From 2a7fee7cc0df347f4441b72e906ff6efed46bc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Tue, 23 Mar 2021 10:42:28 +0100 Subject: [PATCH 85/86] Apply template-patches/ruby-string-index-for-server-variables.patch --- .generator/templates/configuration.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.generator/templates/configuration.mustache b/.generator/templates/configuration.mustache index 9e81074978ca..1684fe081f3d 100644 --- a/.generator/templates/configuration.mustache +++ b/.generator/templates/configuration.mustache @@ -260,7 +260,7 @@ module {{moduleName}} {{#-first}} variables: { {{/-first}} - {{{name}}}: { + '{{{name}}}' => { description: "{{{description}}}{{^description}}No description provided{{/description}}", default_value: "{{{defaultValue}}}", {{#enumValues}} @@ -299,7 +299,7 @@ module {{moduleName}} {{#-first}} variables: { {{/-first}} - {{{name}}}: { + '{{{name}}}' => { description: "{{{description}}}{{^description}}No description provided{{/description}}", default_value: "{{{defaultValue}}}", {{#enumValues}} From 675a265275c77d623dc5f711327d3f73a409b349 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Tue, 23 Mar 2021 14:01:46 +0000 Subject: [PATCH 86/86] Regenerate client from commit 7e667f1 of spec repo --- .apigentools-info | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.apigentools-info b/.apigentools-info index 4fbb6993a29d..58193d7ee9c3 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.4.1.dev6", - "regenerated": "2021-03-23 10:51:50.194106", - "spec_repo_commit": "34cf37f" + "regenerated": "2021-03-23 14:01:30.773317", + "spec_repo_commit": "7e667f1" }, "v2": { "apigentools_version": "1.4.1.dev6", - "regenerated": "2021-03-23 10:52:03.766338", - "spec_repo_commit": "34cf37f" + "regenerated": "2021-03-23 14:01:44.126537", + "spec_repo_commit": "7e667f1" } } } \ No newline at end of file