diff --git a/README.md b/README.md
index 8490369..fd57598 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,21 @@ end
If you don't set them and they are left with default nil values, you will have to use the old way, by manually mount the engine in the Rails routes configuration file (**config/routes.rb**) by following examples below.
+NEW Improvements in version 2.0.0
+---------------------------------
+
+This release tries to fix some major bugs and introduces backward incompatible changes.
+ - The complex type list will contain now exactly same types used when doing an actual SOAP request
+ - Same for when listing the soap actions ( the return type and parameters ).
+
+Initially the way the complex types were shown on the page was not correct, because it was not reflecting
+the actual way the SOAP action receives its arguments when doing an actual SOAP request to that controller
+
+The main issue was not handling correctly the classes that are inheriting from WashOut::Type.
+
+This release tries to fix those issues.
+
+
NEW Improvements in version 1.4.0
---------------------------------
diff --git a/app/helpers/washout_builder_complex_type_helper.rb b/app/helpers/washout_builder_complex_type_helper.rb
index 483ddf6..97416c4 100644
--- a/app/helpers/washout_builder_complex_type_helper.rb
+++ b/app/helpers/washout_builder_complex_type_helper.rb
@@ -1,5 +1,6 @@
# module that is used for constructing complex types in HTML-Documentation
module WashoutBuilderComplexTypeHelper
+ include WashoutBuilderSharedHelper
# this method is for printing the attributes of a complex type
# if the attributes are primitives this will show the attributes with blue color
# otherwise will call another method for printing the complex attribute
@@ -49,8 +50,9 @@ def html_safe(string)
def create_complex_element_type_html(pre, element, element_description)
complex_class = element.find_complex_class_name
return if complex_class.nil?
- complex_class_content = element.multiplied ? "Array of #{complex_class}" : "#{complex_class}"
- pre << "#{complex_class_content} #{element.name}"
+ real_class = find_correct_complex_type(complex_class)
+ complex_class_content = element.multiplied ? "Array of #{real_class}" : "#{real_class}"
+ pre << "#{complex_class_content} #{element.name}"
pre << " #{html_safe(element_description)}" unless element_description.blank?
pre
end
diff --git a/app/helpers/washout_builder_method_arguments_helper.rb b/app/helpers/washout_builder_method_arguments_helper.rb
index 92e6660..c760b78 100644
--- a/app/helpers/washout_builder_method_arguments_helper.rb
+++ b/app/helpers/washout_builder_method_arguments_helper.rb
@@ -1,5 +1,6 @@
# helper that is used to show the arguments of a method with their types in HTML documentation
module WashoutBuilderMethodArgumentsHelper
+ include WashoutBuilderSharedHelper
# displays the parameter of a method as argument and determines if the parameter is basic type or complex type
#
# @see WashoutBuilder::Document::ComplexType#find_complex_class_name
@@ -37,8 +38,9 @@ def create_method_argument_element(pre, param, mlen)
# @api public
def create_method_argument_complex_element(pre, param, use_spacer, spacer, complex_class)
return if complex_class.nil?
- argument_content = param.multiplied ? "Array of #{complex_class}" : "#{complex_class}"
- pre << "#{use_spacer ? spacer : ''}#{argument_content} #{param.name}"
+ real_class = find_correct_complex_type(complex_class)
+ argument_content = param.multiplied ? "Array of #{real_class}" : "#{real_class}"
+ pre << "#{use_spacer ? spacer : ''}#{argument_content} #{param.name}"
end
# this method will check if the current index of the argument is not last, will insert a comma then a break if the argument is followed by other arguments,
diff --git a/app/helpers/washout_builder_method_list_helper.rb b/app/helpers/washout_builder_method_list_helper.rb
index 532577e..dbeaf5a 100644
--- a/app/helpers/washout_builder_method_list_helper.rb
+++ b/app/helpers/washout_builder_method_list_helper.rb
@@ -1,5 +1,6 @@
# helper that is used to list the method's return tyep as a LI element in HTML documentation
module WashoutBuilderMethodListHelper
+ include WashoutBuilderSharedHelper
# this method will create the return type of the method and check if the type is basic or complex type or array of types
#
# @param [Builder::XmlMarkup] xml the markup builder that is used to insert HTML line breaks or span elements
@@ -10,9 +11,10 @@ module WashoutBuilderMethodListHelper
#
# @api public
def create_return_complex_type_list_html(xml, complex_class, builder_out)
- return_content = builder_out[0].multiplied ? "Array of #{complex_class}" : "#{complex_class}"
+ real_class = find_correct_complex_type(complex_class)
+ return_content = builder_out[0].multiplied ? "Array of #{real_class}" : "#{real_class}"
xml.span('class' => 'pre') do
- xml.a('href' => "##{complex_class}") do |inner_xml|
+ xml.a('href' => "##{real_class}") do |inner_xml|
inner_xml.span('class' => 'lightBlue') do |y|
y << "#{return_content}"
end
diff --git a/app/helpers/washout_builder_method_return_type_helper.rb b/app/helpers/washout_builder_method_return_type_helper.rb
index d424a3c..8395199 100644
--- a/app/helpers/washout_builder_method_return_type_helper.rb
+++ b/app/helpers/washout_builder_method_return_type_helper.rb
@@ -1,5 +1,6 @@
# helper that is used to create the return types of methods in HTML documentation
module WashoutBuilderMethodReturnTypeHelper
+ include WashoutBuilderSharedHelper
# this method will print the return type next to the method name
# @see WashoutBuilder::Document::ComplexType#find_complex_class_name
# @see WashoutBuilder::Type::BASIC_TYPES
@@ -37,11 +38,12 @@ def create_html_public_method_return_type(xml, pre, output)
# @api public
def html_public_method_complex_type(pre, output, complex_class)
return if complex_class.nil?
+ real_class = find_correct_complex_type(complex_class)
if output[0].multiplied
- complex_return_type = "Array of #{complex_class}"
+ complex_return_type = "Array of #{real_class}"
else
- complex_return_type = "#{complex_class}"
+ complex_return_type = "#{real_class}"
end
- pre << "#{complex_return_type}"
+ pre << "#{complex_return_type}"
end
end
diff --git a/app/helpers/washout_builder_shared_helper.rb b/app/helpers/washout_builder_shared_helper.rb
new file mode 100644
index 0000000..4d2f17c
--- /dev/null
+++ b/app/helpers/washout_builder_shared_helper.rb
@@ -0,0 +1,29 @@
+module WashoutBuilderSharedHelper
+ # When displaying a complex type that inherits from WashOut::Type
+ # we must use its descendant name to properly show the correct Type
+ # that can we used to make the actual request to the action
+ #
+ # @param [Class, String] complex_class the name of the complex type either as a string or a class
+ # @return [Class, String]
+ # @api public
+ def find_correct_complex_type(complex_class)
+ real_class = find_class_from_string(complex_class)
+ if real_class.present? && real_class.ancestors.include?( WashoutBuilder::Type.base_type_class)
+ descendant = WashoutBuilder::Type.base_param_class.parse_def(config, real_class.wash_out_param_map)[0]
+ descendant.find_complex_class_name
+ else
+ complex_class
+ end
+ end
+
+ # Tries to constantize a string or a class to return the class
+ #
+ # @param [String] complex_class A string that contains the name of a class
+ # @return [Class, nil] returns the class if it is classes_defined otherwise nil
+ # @api public
+ def find_class_from_string(complex_class)
+ complex_class.is_a?(Class) ? complex_class : complex_class.constantize
+ rescue
+ nil
+ end
+end
\ No newline at end of file
diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb
index ad670fd..30cbeca 100644
--- a/lib/washout_builder.rb
+++ b/lib/washout_builder.rb
@@ -52,7 +52,6 @@ def wash_out(controller_name, options={})
base_param_class = WashoutBuilder::Type.base_param_class
if base_param_class.present?
base_param_class.class_eval do
- extend WashoutBuilder::Param
include WashoutBuilder::Document::ComplexType
end
end
diff --git a/lib/washout_builder/document/complex_type.rb b/lib/washout_builder/document/complex_type.rb
index 1c75850..cc3ea58 100644
--- a/lib/washout_builder/document/complex_type.rb
+++ b/lib/washout_builder/document/complex_type.rb
@@ -71,25 +71,6 @@ def remove_type_inheritable_elements(keys)
self.map = map.delete_if { |element| keys.include?(element.name) }
end
- # Dirty hack to fix the first washout param type.
- # This only applies if the first complex type is inheriting WashOutType
- # its name should be set to its descendant and the map of the current object will be set to its descendant
- # @see WashOut::Param#parse_builder_def
- #
- # @param [WashOut::SoapConfig] config an object that holds the soap configuration
- # @param [Class, String] complex_class the name of the complex type either as a string or a class
- # @return [void]
- # @api public
- def fix_descendant_wash_out_type(config, complex_class)
- param_class = find_class_from_string(complex_class)
- base_param_class = WashoutBuilder::Type.base_param_class
- base_type_class = WashoutBuilder::Type.base_type_class
- return if base_param_class.blank? || base_type_class.blank?
- return unless param_class.present? && param_class.ancestors.include?(base_type_class) && map[0].present?
- descendant = base_param_class.parse_builder_def(config, param_class.wash_out_param_map)[0]
- self.name = descendant.name
- self.map = descendant.map
- end
# Description of method
#
@@ -172,8 +153,8 @@ def complex_type_descendants(config, classes_defined)
def get_nested_complex_types(config, classes_defined)
classes_defined = [] if classes_defined.blank?
complex_class = find_complex_class_name(classes_defined)
- fix_descendant_wash_out_type(config, complex_class)
- unless complex_class.nil?
+ real_class = find_class_from_string(complex_class)
+ if complex_class.present? && (real_class.blank? || (real_class.present? && !real_class.ancestors.include?( WashoutBuilder::Type.base_type_class)))
classes_defined << complex_type_hash(complex_class, self, complex_type_ancestors(config, complex_class, classes_defined))
end
classes_defined = complex_type_descendants(config, classes_defined)
diff --git a/lib/washout_builder/param.rb b/lib/washout_builder/param.rb
deleted file mode 100644
index 5d4a213..0000000
--- a/lib/washout_builder/param.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module WashoutBuilder
- # module that extends the base WashoutParam to allow parsing of definitions for building documentation
- module Param
- extend ActiveSupport::Concern
-
- # Method that receives the arguments for a soap action (input or output) and tries to parse the definition (@see WashOutParam#parse_def)
- #
- # the following lines was removed from original method because when generating the documentation
- # the "source_class" attrtibute of the object was not the name of the class of the complex tyoe
- # but instead was the name given in the hash
- #
- # if definition.is_a?(Class) && definition.ancestors.include?(WashOut::Type)
- # definition = definition.wash_out_param_map
- # end
- #
- # @example Given the class ProjectType as a "definition" argument, the complex type name should be ProjectType and not "project"
- # class ProjectType < WashOut::Type
- # map :project => {
- # :name => :string,
- # :description => :string,
- # :users => [{:mail => :string }],
- # }
- # end
- #
- #
- # @see WashoutBuilder::SOAP#soap_action
- # @see WashOutParam#initialize
- #
- # @param [WasOut::SoapConfig] soap_config Holds the soap configuration for the entire web service
- # @param [Object] definition Any type of object ( this is passed from the soap action)
- #
- # @return [Type] description of returned object
- def parse_builder_def(soap_config, definition)
- raise '[] should not be used in your params. Use nil if you want to mark empty set.' if definition == []
- return [] if definition.blank?
-
- definition = { value: definition } unless definition.is_a?(Hash) # for arrays and symbols
-
- definition.map do |name, opt|
- if opt.is_a? self
- opt
- elsif opt.is_a? Array
- new(soap_config, name, opt[0], true)
- else
- new(soap_config, name, opt)
- end
- end
- end
- end
-end
diff --git a/lib/washout_builder/soap.rb b/lib/washout_builder/soap.rb
index f98a92a..6ce4f90 100644
--- a/lib/washout_builder/soap.rb
+++ b/lib/washout_builder/soap.rb
@@ -37,8 +37,8 @@ def builder_soap_action(action, options = {})
current_action = soap_actions[action]
base_param_class = WashoutBuilder::Type.base_param_class
return if base_param_class.blank?
- current_action[:builder_in] = base_param_class.parse_builder_def(soap_config, options[:args])
- current_action[:builder_out] = base_param_class.parse_builder_def(soap_config, options[:return])
+ current_action[:builder_in] = base_param_class.parse_def(soap_config, options[:args])
+ current_action[:builder_out] = base_param_class.parse_def(soap_config, options[:return])
current_action[:args_description] = options[:args_description].present? && options[:args_description].is_a?(Hash) ? options[:args_description].stringify_keys : {}
current_action
end
diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb
index 845ea47..182bdc2 100644
--- a/lib/washout_builder/version.rb
+++ b/lib/washout_builder/version.rb
@@ -8,11 +8,11 @@ def self.gem_version
# the module that is used to generate the gem version
module VERSION
# the major version of the gem
- MAJOR = 1
+ MAJOR = 2
# the minor version of the gem
- MINOR = 7
+ MINOR = 0
# the tiny version of the gem
- TINY = 5
+ TINY = 0
# if the version should be a prerelease
PRE = nil