From 407f9de8cc016acd286d97aa5a468150db404138 Mon Sep 17 00:00:00 2001 From: Panos Dalitsouris Date: Tue, 27 Dec 2022 18:10:01 +0200 Subject: [PATCH 1/4] Encapsulate Swagger warning logic to dedicated classes --- lib/apipie-rails.rb | 4 + lib/apipie/generator/swagger/warning.rb | 77 +++++++++++++++++ .../generator/swagger/warning_writer.rb | 48 +++++++++++ lib/apipie/swagger_generator.rb | 86 ++++++++++++++----- spec/lib/generator/swagger/warning_spec.rb | 51 +++++++++++ .../generator/swagger/warning_writer_spec.rb | 59 +++++++++++++ 6 files changed, 303 insertions(+), 22 deletions(-) create mode 100644 lib/apipie/generator/swagger/warning.rb create mode 100644 lib/apipie/generator/swagger/warning_writer.rb create mode 100644 spec/lib/generator/swagger/warning_spec.rb create mode 100644 spec/lib/generator/swagger/warning_writer_spec.rb diff --git a/lib/apipie-rails.rb b/lib/apipie-rails.rb index 840ad5ba..5e647fc2 100644 --- a/lib/apipie-rails.rb +++ b/lib/apipie-rails.rb @@ -23,3 +23,7 @@ require 'apipie/extractor' require "apipie/version" require "apipie/swagger_generator" +require "apipie/generator/generator" +require "apipie/generator/swagger/swagger" +require "apipie/generator/swagger/warning" +require "apipie/generator/swagger/warning_writer" diff --git a/lib/apipie/generator/swagger/warning.rb b/lib/apipie/generator/swagger/warning.rb new file mode 100644 index 00000000..41d202d5 --- /dev/null +++ b/lib/apipie/generator/swagger/warning.rb @@ -0,0 +1,77 @@ +class Apipie::Generator::Swagger::Warning + MISSING_METHOD_SUMMARY_CODE = 100 + ADDED_MISSING_SLASH_CODE = 101 + NO_RETURN_CODES_SPECIFIED_CODE = 102 + HASH_WITHOUT_INTERNAL_TYPESPEC_CODE = 103 + OPTIONAL_PARAM_IN_PATH_CODE = 104 + OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE = 105 + PARAM_IGNORED_IN_FORM_DATA_CODE = 106 + PATH_PARAM_NOT_DESCRIBED_CODE = 107 + INFERRING_BOOLEAN_CODE = 108 + + CODES = { + missing_method_summary: MISSING_METHOD_SUMMARY_CODE, + added_missing_slash: ADDED_MISSING_SLASH_CODE, + no_return_codes_specified: NO_RETURN_CODES_SPECIFIED_CODE, + hash_without_internal_typespec: HASH_WITHOUT_INTERNAL_TYPESPEC_CODE, + optional_param_in_path: OPTIONAL_PARAM_IN_PATH_CODE, + optional_without_default_value: OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE, + param_ignored_in_form_data: PARAM_IGNORED_IN_FORM_DATA_CODE, + path_param_not_described_code: PATH_PARAM_NOT_DESCRIBED_CODE, + inferring_boolean: INFERRING_BOOLEAN_CODE + } + + MESSAGES = { + MISSING_METHOD_SUMMARY_CODE => "Missing short description for method", + ADDED_MISSING_SLASH_CODE => "Added missing / at beginning of path: %{path}", + HASH_WITHOUT_INTERNAL_TYPESPEC_CODE => "The parameter :%{parameter} is a generic Hash without an internal type specification", + NO_RETURN_CODES_SPECIFIED_CODE => "No return codes ('errors') specified", + OPTIONAL_PARAM_IN_PATH_CODE => "The parameter :%{parameter} is 'in-path'. Ignoring 'not required' in DSL", + OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE => "The parameter :%{parameter} is optional but default value is not specified (use :default_value => ...)", + PARAM_IGNORED_IN_FORM_DATA_CODE => "Ignoring param :%{parameter} -- cannot include Hash without fields in a formData specification", + PATH_PARAM_NOT_DESCRIBED_CODE => "The parameter :%{name} appears in the path %{path} but is not described", + INFERRING_BOOLEAN_CODE => "The parameter [%{parameter}] is Enum with [true, false] values. Inferring 'boolean'" + } + + attr_reader :code + + def initialize(code, info_message, method_id) + @code = code + @info_message = info_message + @method_id = method_id + end + + def id + "#{@method_id}#{@code}#{@info_message}" + end + + def warning_message + "WARNING (#{@code}): [#{@method_id}] -- #{@info_message}" + end + + def warn + Warning.warn(warning_message) + end + + def warn_through_writer + Apipie::Generator::Swagger::WarningWriter.instance.warn(self) + end + + # @param [Integer] code + # @param [Hash] message_attributes + # + # @return [Apipie::Generator::Swagger::Warning] + def self.for_code(code, method_id, message_attributes = {}) + if !CODES.values.include?(code) + raise ArgumentError, 'Unknown warning code' + end + + info_message = if message_attributes.present? + self::MESSAGES[code] % message_attributes + else + self::MESSAGES[code] + end + + Apipie::Generator::Swagger::Warning.new(code, info_message, method_id) + end +end diff --git a/lib/apipie/generator/swagger/warning_writer.rb b/lib/apipie/generator/swagger/warning_writer.rb new file mode 100644 index 00000000..9ae489b1 --- /dev/null +++ b/lib/apipie/generator/swagger/warning_writer.rb @@ -0,0 +1,48 @@ +class Apipie::Generator::Swagger::WarningWriter + include Singleton + + def initialize + @issued_warnings = [] + end + + # @param [Apipie::Generator::Swagger::Warning] warning + def warn(warning) + return if muted_warning?(warning) + + warning.warn + + @issued_warnings << warning.id + end + + def issued_warnings? + @issued_warnings.count > 0 + end + + private + + # @param [Apipie::Generator::Swagger::Warning] warning + # + # @return [TrueClass, FalseClass] + def muted_warning?(warning) + @issued_warnings.include?(warning.id) || + suppressed_warning?(warning.code) || + suppress_warnings? + end + + # @param [Integer] warning_number + # + # @return [TrueClass, FalseClass] + def suppressed_warning?(warning_number) + suppress_warnings_config.is_a?(Array) && suppress_warnings_config.include?(warning_number) + end + + # @return [TrueClass, FalseClass] + def suppress_warnings? + suppress_warnings_config == true + end + + # @return [FalseClass, TrueClass, Array] + def suppress_warnings_config + Apipie.configuration.swagger_suppress_warnings + end +end diff --git a/lib/apipie/swagger_generator.rb b/lib/apipie/swagger_generator.rb index 0f73be14..d1e9d1f5 100644 --- a/lib/apipie/swagger_generator.rb +++ b/lib/apipie/swagger_generator.rb @@ -128,33 +128,75 @@ def ruby_name_for_method(method) method.resource.controller.name + "#" + method.method end + def warn_missing_method_summary + warn(Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE) + end + + def warn_added_missing_slash(path) + warn( + Apipie::Generator::Swagger::Warning::ADDED_MISSING_SLASH_CODE, + { path: path } + ) + end - def warn_missing_method_summary() warn 100, "missing short description for method"; end - def warn_added_missing_slash(path) warn 101,"added missing / at beginning of path: #{path}"; end - def warn_no_return_codes_specified() warn 102,"no return codes ('errors') specified"; end - def warn_hash_without_internal_typespec(param_name) warn 103,"the parameter :#{param_name} is a generic Hash without an internal type specification"; end - def warn_optional_param_in_path(param_name) warn 104, "the parameter :#{param_name} is 'in-path'. Ignoring 'not required' in DSL"; end - def warn_optional_without_default_value(param_name) warn 105,"the parameter :#{param_name} is optional but default value is not specified (use :default_value => ...)"; end - def warn_param_ignored_in_form_data(param_name) warn 106,"ignoring param :#{param_name} -- cannot include Hash without fields in a formData specification"; end - def warn_path_parameter_not_described(name,path) warn 107,"the parameter :#{name} appears in the path #{path} but is not described"; end - def warn_inferring_boolean(name) warn 108,"the parameter [#{name}] is Enum with [true,false] values. Inferring 'boolean'"; end + def warn_no_return_codes_specified + warn(Apipie::Generator::Swagger::Warning::NO_RETURN_CODES_SPECIFIED_CODE) + end - def warn(warning_num, msg) - suppress = Apipie.configuration.swagger_suppress_warnings - return if suppress == true - return if suppress.is_a?(Array) && suppress.include?(warning_num) + def warn_hash_without_internal_typespec(param_name) + warn( + Apipie::Generator::Swagger::Warning::HASH_WITHOUT_INTERNAL_TYPESPEC_CODE, + { parameter: param_name } + ) + end - method_id = ruby_name_for_method(@current_method) - warning_id = "#{method_id}#{warning_num}#{msg}" + def warn_optional_param_in_path(param_name) + warn( + Apipie::Generator::Swagger::Warning::OPTIONAL_PARAM_IN_PATH_CODE, + { parameter: param_name } + ) + end - if @issued_warnings.include?(warning_id) - # Already issued this warning for the current method - return - end + def warn_optional_without_default_value(param_name) + warn( + Apipie::Generator::Swagger::Warning::OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE, + { parameter: param_name } + ) + end + + def warn_param_ignored_in_form_data(param_name) + warn( + Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE, + { parameter: param_name } + ) + end + + def warn_path_parameter_not_described(name, path) + warn( + Apipie::Generator::Swagger::Warning::PATH_PARAM_NOT_DESCRIBED_CODE, + { name: name, path: path } + ) + end + + def warn_inferring_boolean(name) + warn( + Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE, + { name: name } + ) + end + + # @param [Integer] warning_code + # @param [Hash] message_attributes + def warn(warning_code, message_attributes = {}) + Apipie::Generator::Swagger::Warning.for_code( + warning_code, + ruby_name_for_method(@current_method), + message_attributes + ).warn_through_writer - print "WARNING (#{warning_num}): [#{method_id}] -- #{msg}\n" - @issued_warnings.push(warning_id) - @warnings_issued = true + @warnings_issued = Apipie::Generator::Swagger::WarningWriter. + instance. + issued_warnings? end def info(msg) diff --git a/spec/lib/generator/swagger/warning_spec.rb b/spec/lib/generator/swagger/warning_spec.rb new file mode 100644 index 00000000..28a356e1 --- /dev/null +++ b/spec/lib/generator/swagger/warning_spec.rb @@ -0,0 +1,51 @@ +require "spec_helper" + +describe Apipie::Generator::Swagger::Warning do + let(:code) { Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE } + let(:method_id) { 'Examples#index' } + let(:info_message) { 'Something went wrong' } + + let(:warning) { described_class.new(code, info_message, method_id) } + + describe '#id' do + subject { warning.id } + + it { is_expected.to eq("#{method_id}#{code}#{info_message}") } + end + + describe '#warning_message' do + subject { warning.warning_message } + + it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}") } + end + + describe '#warn' do + subject { warning.warn } + + it 'outputs the warning' do + expect { subject }.to output(warning.warning_message).to_stderr + end + end + + describe '#warn_through_writer' do + subject { warning.warn } + + it 'outputs the warning' do + expect { subject }.to output(warning.warning_message).to_stderr + end + end + + describe '.for_code' do + subject { described_class.for_code(code, method_id) } + + it { is_expected.to be_an_instance_of(described_class)} + + context 'when code is invalid' do + let(:code) { 12345 } + + it 'raises an argument error' do + expect { subject }.to raise_error(ArgumentError) + end + end + end +end diff --git a/spec/lib/generator/swagger/warning_writer_spec.rb b/spec/lib/generator/swagger/warning_writer_spec.rb new file mode 100644 index 00000000..c2aaf8be --- /dev/null +++ b/spec/lib/generator/swagger/warning_writer_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe Apipie::Generator::Swagger::WarningWriter do + let(:writer) { described_class.clone.instance } + + let(:warning) do + Apipie::Generator::Swagger::Warning.for_code( + Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE, + 'SampleController#action', + { parameter: 'some-param' } + ) + end + + before do + Apipie.configuration.swagger_suppress_warnings = false + Singleton.__init__(described_class) + end + + describe '#warn' do + subject { writer.warn(warning) } + + it 'outputs the warning' do + expect { subject }.to output(warning.warning_message).to_stderr + end + + context 'when Apipie.configuration.swagger_suppress_warnings is true' do + before { Apipie.configuration.swagger_suppress_warnings = true } + + it { is_expected.to be_falsey } + end + + context 'when Apipie.configuration.swagger_suppress_warnings includes warning code' do + before do + Apipie.configuration.swagger_suppress_warnings = + Array(Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE) + end + + it { is_expected.to be_falsey } + end + + context 'when a warning already been logged' do + before { writer.warn(warning) } + + it { is_expected.to be_falsey } + end + end + + describe '#issued_warnings?' do + subject { writer.issued_warnings? } + + it { is_expected.to be_falsey } + + context 'when a warning already been logged' do + before { writer.warn(warning) } + + it { is_expected.to be_truthy } + end + end +end From 4d8688ed22c645d63d3f67bdff6d3643d24a7440 Mon Sep 17 00:00:00 2001 From: Panos Dalitsouris Date: Tue, 27 Dec 2022 08:08:26 +0200 Subject: [PATCH 2/4] Move Swagger type decision logic to dedicated classes. `Apipie::Generator::Swagger::TypeExtractor` is responsible to identify the Swagger type from a given validator or default to `string` if no validator is given. --- lib/apipie-rails.rb | 2 + lib/apipie/generator/generator.rb | 2 + lib/apipie/generator/swagger/swagger.rb | 2 + lib/apipie/generator/swagger/type.rb | 16 +++++ .../generator/swagger/type_extractor.rb | 69 +++++++++++++++++++ lib/apipie/swagger_generator.rb | 69 +++---------------- .../generator/swagger/type_extractor_spec.rb | 61 ++++++++++++++++ 7 files changed, 163 insertions(+), 58 deletions(-) create mode 100644 lib/apipie/generator/generator.rb create mode 100644 lib/apipie/generator/swagger/swagger.rb create mode 100644 lib/apipie/generator/swagger/type.rb create mode 100644 lib/apipie/generator/swagger/type_extractor.rb create mode 100644 spec/lib/generator/swagger/type_extractor_spec.rb diff --git a/lib/apipie-rails.rb b/lib/apipie-rails.rb index 5e647fc2..27ea554a 100644 --- a/lib/apipie-rails.rb +++ b/lib/apipie-rails.rb @@ -27,3 +27,5 @@ require "apipie/generator/swagger/swagger" require "apipie/generator/swagger/warning" require "apipie/generator/swagger/warning_writer" +require "apipie/generator/swagger/type" +require "apipie/generator/swagger/type_extractor" diff --git a/lib/apipie/generator/generator.rb b/lib/apipie/generator/generator.rb new file mode 100644 index 00000000..548157f3 --- /dev/null +++ b/lib/apipie/generator/generator.rb @@ -0,0 +1,2 @@ +module Apipie::Generator +end diff --git a/lib/apipie/generator/swagger/swagger.rb b/lib/apipie/generator/swagger/swagger.rb new file mode 100644 index 00000000..b4b64ad5 --- /dev/null +++ b/lib/apipie/generator/swagger/swagger.rb @@ -0,0 +1,2 @@ +module Apipie::Generator::Swagger +end diff --git a/lib/apipie/generator/swagger/type.rb b/lib/apipie/generator/swagger/type.rb new file mode 100644 index 00000000..a94bbc33 --- /dev/null +++ b/lib/apipie/generator/swagger/type.rb @@ -0,0 +1,16 @@ +class Apipie::Generator::Swagger::Type + attr_reader :str_format + + def initialize(type, str_format = nil) + @type = type + @str_format = str_format + end + + def to_s + @type + end + + def ==(other) + other.to_s == self.to_s + end +end diff --git a/lib/apipie/generator/swagger/type_extractor.rb b/lib/apipie/generator/swagger/type_extractor.rb new file mode 100644 index 00000000..b649c5cd --- /dev/null +++ b/lib/apipie/generator/swagger/type_extractor.rb @@ -0,0 +1,69 @@ +class Apipie::Generator::Swagger::TypeExtractor + TYPES = { + numeric: 'number', + hash: 'object', + array: 'array', + enum: 'enum', + + # see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types + integer: Apipie::Generator::Swagger::Type.new('integer', 'int32'), + long: Apipie::Generator::Swagger::Type.new('integer', 'int64'), + number: Apipie::Generator::Swagger::Type.new('number'), + float: Apipie::Generator::Swagger::Type.new('number', 'float'), + double: Apipie::Generator::Swagger::Type.new('number', 'double'), + string: Apipie::Generator::Swagger::Type.new('string'), + byte: Apipie::Generator::Swagger::Type.new('string', 'byte'), + binary: Apipie::Generator::Swagger::Type.new('string', 'binary'), + boolean: Apipie::Generator::Swagger::Type.new('boolean'), + date: Apipie::Generator::Swagger::Type.new('string', 'date'), + dateTime: Apipie::Generator::Swagger::Type.new('string', 'date-time'), + password: Apipie::Generator::Swagger::Type.new('string', 'password') + } + + # @param [] validator + def initialize(validator) + @validator = validator + end + + # @param [Hash] warnings + def extract_with_warnings(warnings = {}) + if boolean? && warnings[:boolean].present? + Apipie::Generator::Swagger::WarningWriter.instance.warn(warnings[:boolean]) + end + + extract + end + + private + + def extract + expected_type = if string? + :string + elsif boolean? + :boolean + elsif enum? + :enum + else + @validator.expected_type.to_sym + end + + TYPES[expected_type] || @validator.expected_type + end + + def string? + @validator.blank? + end + + def enum? + @validator.is_a?(Apipie::Validator::EnumValidator) || + (@validator.respond_to?(:is_enum?) && @validator.is_enum?) + end + + def boolean? + @_boolean ||= enum? && boolean_values? + end + + def boolean_values? + @validator.values.to_set == Set.new([true, false]) + end +end diff --git a/lib/apipie/swagger_generator.rb b/lib/apipie/swagger_generator.rb index d1e9d1f5..893826b0 100644 --- a/lib/apipie/swagger_generator.rb +++ b/lib/apipie/swagger_generator.rb @@ -318,68 +318,21 @@ def swagger_op_id_for_path(http_method, path) http_method.downcase + path.gsub(/\//,'_').gsub(/:(\w+)/, '\1').gsub(/_$/,'') end - class SwaggerTypeWithFormat - attr_reader :str_format - def initialize(type, str_format) - @type = type - @str_format = str_format - end - - def to_s - @type - end - - def ==(other) - other.to_s == self.to_s - end - end - - def lookup - @lookup ||= { - numeric: "number", - hash: "object", - array: "array", - - # see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types - integer: SwaggerTypeWithFormat.new("integer", "int32"), - long: SwaggerTypeWithFormat.new("integer", "int64"), - number: SwaggerTypeWithFormat.new("number", nil), # here just for completeness - float: SwaggerTypeWithFormat.new("number", "float"), - double: SwaggerTypeWithFormat.new("number", "double"), - string: SwaggerTypeWithFormat.new("string", nil), # here just for completeness - byte: SwaggerTypeWithFormat.new("string", "byte"), - binary: SwaggerTypeWithFormat.new("string", "binary"), - boolean: SwaggerTypeWithFormat.new("boolean", nil), # here just for completeness - date: SwaggerTypeWithFormat.new("string", "date"), - dateTime: SwaggerTypeWithFormat.new("string", "date-time"), - password: SwaggerTypeWithFormat.new("string", "password"), - } - end - - def swagger_param_type(param_desc) - if param_desc.nil? - raise("problem") + if param_desc.blank? + raise ArgumentError, 'param_desc is required' end - v = param_desc.validator - if v.nil? - return "string" - end - - if v.class == Apipie::Validator::EnumValidator || (v.respond_to?(:is_enum?) && v.is_enum?) - if v.values - [true, false] == [] && [true, false] - v.values == [] - warn_inferring_boolean(param_desc.name) - return "boolean" - else - return "enum" - end - elsif v.class == Apipie::Validator::HashValidator - # pp v - end + method_id = ruby_name_for_method(@current_method) + warning = Apipie::Generator::Swagger::Warning.for_code( + Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE, + method_id, + { parameter: param_desc.name } + ) - return lookup[v.expected_type.to_sym] || v.expected_type + Apipie::Generator::Swagger::TypeExtractor.new(param_desc.validator). + extract_with_warnings({ boolean: warning }) end @@ -515,7 +468,7 @@ def save_field(entry, openapi_key, v, apipie_key=openapi_key, translate=false) swg_param_type = swagger_param_type(param_desc) swagger_def[:type] = swg_param_type.to_s - if (swg_param_type.is_a? SwaggerTypeWithFormat) && !swg_param_type.str_format.nil? + if (swg_param_type.is_a? Apipie::Generator::Swagger::Type) && !swg_param_type.str_format.nil? swagger_def[:format] = swg_param_type.str_format end diff --git a/spec/lib/generator/swagger/type_extractor_spec.rb b/spec/lib/generator/swagger/type_extractor_spec.rb new file mode 100644 index 00000000..ab7fdc6f --- /dev/null +++ b/spec/lib/generator/swagger/type_extractor_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Apipie::Generator::Swagger::TypeExtractor do + let(:validator) {} + let(:extractor) { described_class.new(validator) } + + describe '#extarct_with_warnings' do + let(:warnings) { {} } + + before { Apipie.configuration.swagger_suppress_warnings = false } + + subject { extractor.extract_with_warnings(warnings) } + + it { is_expected.to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]) } + + context "when enum validator is used" do + let(:enum_values) { ["Name"] } + + context "of type Apipie::Validator::EnumValidator" do + let(:validator) { Apipie::Validator::EnumValidator.new(nil, enum_values) } + + it { is_expected.to eq("enum") } + end + + context "that responds to is_enum?" do + let(:validator) do + Apipie::ResponseDescriptionAdapter::PropDesc::Validator.new('some-type', enum_values) + end + + it 'returns an enum type' do + expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:enum]) + end + + context 'and has `true`, `false` as values' do + let(:param_description_name) { :visible } + let(:enum_values) { [true, false] } + + it 'returns a boolean type' do + expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:boolean]) + end + + context 'and a boolean warning is passed' do + let(:boolean_warning) do + Apipie::Generator::Swagger::Warning.for_code( + Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE, + 'SampleController#action', + { parameter: 'some-param' } + ) + end + + let(:warnings) { { boolean: boolean_warning } } + + it 'outputs the warning' do + expect { subject }.to output(boolean_warning.warning_message).to_stderr + end + end + end + end + end + end +end From 036e7489efb8399c8bd868a0072c59ac745b7129 Mon Sep 17 00:00:00 2001 From: Panos Dalitsouris Date: Wed, 28 Dec 2022 06:56:24 +0200 Subject: [PATCH 3/4] fixup! Move Swagger type decision logic to dedicated classes. --- .../generator/swagger/type_extractor.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/apipie/generator/swagger/type_extractor.rb b/lib/apipie/generator/swagger/type_extractor.rb index b649c5cd..a465941d 100644 --- a/lib/apipie/generator/swagger/type_extractor.rb +++ b/lib/apipie/generator/swagger/type_extractor.rb @@ -37,15 +37,16 @@ def extract_with_warnings(warnings = {}) private def extract - expected_type = if string? - :string - elsif boolean? - :boolean - elsif enum? - :enum - else - @validator.expected_type.to_sym - end + expected_type = + if string? + :string + elsif boolean? + :boolean + elsif enum? + :enum + else + @validator.expected_type.to_sym + end TYPES[expected_type] || @validator.expected_type end From dc88775d6adbbea6f038b83ae93abd2446207169 Mon Sep 17 00:00:00 2001 From: Panos Dalitsouris Date: Wed, 28 Dec 2022 07:22:48 +0200 Subject: [PATCH 4/4] fixup! Move Swagger type decision logic to dedicated classes. Update Yard comment --- lib/apipie/generator/swagger/type_extractor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/apipie/generator/swagger/type_extractor.rb b/lib/apipie/generator/swagger/type_extractor.rb index a465941d..a8286a92 100644 --- a/lib/apipie/generator/swagger/type_extractor.rb +++ b/lib/apipie/generator/swagger/type_extractor.rb @@ -20,7 +20,7 @@ class Apipie::Generator::Swagger::TypeExtractor password: Apipie::Generator::Swagger::Type.new('string', 'password') } - # @param [] validator + # @param [Apipie::Validator::BaseValidator, ResponseDescriptionAdapter::PropDesc::Validator, nil] validator def initialize(validator) @validator = validator end