From 82301545794462f3e1b6fde86ec857bf983c46b3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 1 Dec 2025 00:48:13 +0100 Subject: [PATCH 1/2] [crystal] implement "multi" params See: https://github.com/mamantoha/crest?tab=readme-ov-file#crestnestedparamsencoder --- .../src/main/resources/crystal/api.mustache | 2 +- .../main/resources/crystal/api_client.mustache | 6 +++--- .../crystal/src/petstore/api/fake_api.cr | 2 +- .../petstore/crystal/src/petstore/api/pet_api.cr | 16 ++++++++-------- .../crystal/src/petstore/api/store_api.cr | 8 ++++---- .../crystal/src/petstore/api/user_api.cr | 16 ++++++++-------- .../petstore/crystal/src/petstore/api_client.cr | 6 +++--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/crystal/api.mustache b/modules/openapi-generator/src/main/resources/crystal/api.mustache index 0bf7d2dea886..01a51a2d028f 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api.mustache @@ -131,7 +131,7 @@ module {{moduleName}} cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new {{#queryParams}} query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}) unless {{{paramName}}}.nil?{{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}} {{/queryParams}} diff --git a/modules/openapi-generator/src/main/resources/crystal/api_client.mustache b/modules/openapi-generator/src/main/resources/crystal/api_client.mustache index b74d38f191b3..dcfecda0b783 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api_client.mustache @@ -109,8 +109,7 @@ module {{moduleName}} when :pipes param.join("|") when :multi - # TODO: Need to fix this - raise "multi is not supported yet" + param else raise "unknown collection format: #{collection_format.inspect}" end @@ -147,7 +146,8 @@ module {{moduleName}} cookies: cookie_params, form: form_or_body, logging: @config.debugging, - handle_errors: false + handle_errors: false, + params_encoder: Crest::NestedParamsEncoder ) response = request.execute diff --git a/samples/client/petstore/crystal/src/petstore/api/fake_api.cr b/samples/client/petstore/crystal/src/petstore/api/fake_api.cr index d9c592b9eee4..187ada7773d8 100644 --- a/samples/client/petstore/crystal/src/petstore/api/fake_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/fake_api.cr @@ -67,7 +67,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new query_params["type"] = _type.to_s unless _type.nil? query_params["http_debug_option"] = http_debug_option.to_s unless http_debug_option.nil? diff --git a/samples/client/petstore/crystal/src/petstore/api/pet_api.cr b/samples/client/petstore/crystal/src/petstore/api/pet_api.cr index ff7edcc479bf..f8b3c5bb597a 100644 --- a/samples/client/petstore/crystal/src/petstore/api/pet_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/pet_api.cr @@ -45,7 +45,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -110,7 +110,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -172,7 +172,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new query_params["status"] = @api_client.build_collection_param(status, :csv) unless status.nil? # header parameters @@ -236,7 +236,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new query_params["tags"] = @api_client.build_collection_param(tags, :csv) unless tags.nil? # header parameters @@ -300,7 +300,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -363,7 +363,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -428,7 +428,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -493,7 +493,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new diff --git a/samples/client/petstore/crystal/src/petstore/api/store_api.cr b/samples/client/petstore/crystal/src/petstore/api/store_api.cr index 9540fed78e45..a7475fb150b3 100644 --- a/samples/client/petstore/crystal/src/petstore/api/store_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/store_api.cr @@ -45,7 +45,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -100,7 +100,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -171,7 +171,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -234,7 +234,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new diff --git a/samples/client/petstore/crystal/src/petstore/api/user_api.cr b/samples/client/petstore/crystal/src/petstore/api/user_api.cr index f0d722bb3f44..00235dfb55f6 100644 --- a/samples/client/petstore/crystal/src/petstore/api/user_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/user_api.cr @@ -45,7 +45,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -108,7 +108,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -171,7 +171,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -234,7 +234,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -295,7 +295,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -369,7 +369,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new query_params["username"] = username.to_s unless username.nil? query_params["password"] = password.to_s unless password.nil? @@ -428,7 +428,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new @@ -495,7 +495,7 @@ module Petstore cookie_params = Hash(String, String).new # query parameters - query_params = Hash(String, String).new + query_params = Hash(String, String | Array(String)).new # header parameters header_params = Hash(String, String).new diff --git a/samples/client/petstore/crystal/src/petstore/api_client.cr b/samples/client/petstore/crystal/src/petstore/api_client.cr index 16153a6bf44a..03d02b6d1245 100644 --- a/samples/client/petstore/crystal/src/petstore/api_client.cr +++ b/samples/client/petstore/crystal/src/petstore/api_client.cr @@ -117,8 +117,7 @@ module Petstore when :pipes param.join("|") when :multi - # TODO: Need to fix this - raise "multi is not supported yet" + param else raise "unknown collection format: #{collection_format.inspect}" end @@ -155,7 +154,8 @@ module Petstore cookies: cookie_params, form: form_or_body, logging: @config.debugging, - handle_errors: false + handle_errors: false, + params_encoder: Crest::NestedParamsEncoder ) response = request.execute From e37035020c75612fdf1c2b970768f1614bb83d6a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 1 Dec 2025 01:43:18 +0100 Subject: [PATCH 2/2] [crystal] remove useless templates (imported from ruby) --- .../main/resources/crystal/Gemfile.mustache | 9 ----- .../main/resources/crystal/Rakefile.mustache | 10 ------ .../crystal/configuration_spec.mustache | 35 ------------------- ...configuration_tls_faraday_partial.mustache | 29 --------------- ...onfiguration_tls_typhoeus_partial.mustache | 34 ------------------ .../main/resources/crystal/version.mustache | 5 --- 6 files changed, 122 deletions(-) delete mode 100644 modules/openapi-generator/src/main/resources/crystal/Gemfile.mustache delete mode 100644 modules/openapi-generator/src/main/resources/crystal/Rakefile.mustache delete mode 100644 modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache delete mode 100644 modules/openapi-generator/src/main/resources/crystal/configuration_tls_faraday_partial.mustache delete mode 100644 modules/openapi-generator/src/main/resources/crystal/configuration_tls_typhoeus_partial.mustache delete mode 100644 modules/openapi-generator/src/main/resources/crystal/version.mustache diff --git a/modules/openapi-generator/src/main/resources/crystal/Gemfile.mustache b/modules/openapi-generator/src/main/resources/crystal/Gemfile.mustache deleted file mode 100644 index c2e3127cdcfe..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/Gemfile.mustache +++ /dev/null @@ -1,9 +0,0 @@ -source 'https://rubygems.org' - -gemspec - -group :development, :test do - gem 'rake', '~> 13.0.1' - gem 'pry-byebug' - gem 'rubocop', '~> 0.66.0' -end diff --git a/modules/openapi-generator/src/main/resources/crystal/Rakefile.mustache b/modules/openapi-generator/src/main/resources/crystal/Rakefile.mustache deleted file mode 100644 index c72ca30d454e..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/Rakefile.mustache +++ /dev/null @@ -1,10 +0,0 @@ -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/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache b/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache deleted file mode 100644 index 49a9525703d3..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/configuration_spec.mustache +++ /dev/null @@ -1,35 +0,0 @@ -=begin -{{> api_info}} - -=end - -require 'spec_helper' - -Spectator.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/modules/openapi-generator/src/main/resources/crystal/configuration_tls_faraday_partial.mustache b/modules/openapi-generator/src/main/resources/crystal/configuration_tls_faraday_partial.mustache deleted file mode 100644 index c35c988f9330..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/configuration_tls_faraday_partial.mustache +++ /dev/null @@ -1,29 +0,0 @@ - ### 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] - #TODO 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. - # - #TODO 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 - #TODO attr_accessor :ssl_ca_file - - ### TLS/SSL setting - # Client certificate file (for client certificate) - #TODO attr_accessor :ssl_client_cert - - ### TLS/SSL setting - # Client private key file (for client certificate) - #TODO attr_accessor :ssl_client_key diff --git a/modules/openapi-generator/src/main/resources/crystal/configuration_tls_typhoeus_partial.mustache b/modules/openapi-generator/src/main/resources/crystal/configuration_tls_typhoeus_partial.mustache deleted file mode 100644 index 1ab1b2d03079..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/configuration_tls_typhoeus_partial.mustache +++ /dev/null @@ -1,34 +0,0 @@ - ### 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] - #TODO 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] - # TODO 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 - # TODO attr_accessor :ssl_ca_cert - - ### TLS/SSL setting - # Client certificate file (for client certificate) - # TODO attr_accessor :cert_file - - ### TLS/SSL setting - # Client private key file (for client certificate) - # TODO attr_accessor :key_file diff --git a/modules/openapi-generator/src/main/resources/crystal/version.mustache b/modules/openapi-generator/src/main/resources/crystal/version.mustache deleted file mode 100644 index 9be1d633971f..000000000000 --- a/modules/openapi-generator/src/main/resources/crystal/version.mustache +++ /dev/null @@ -1,5 +0,0 @@ -# {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}} - -module {{moduleName}} - VERSION = '{{shardVersion}}' -end