module Soaspec module WsdlGenerator def try_enum_for(type) custom_type = @wsdl_schemas.xpath("//*[@name='#{type}']") if custom_type.first prefix = custom_type.first.namespace.prefix enumerations = custom_type.xpath("//#{prefix}:enumeration") return 'Custom Type' if enumerations.empty? @enums_values = Array.new enumerations.each do |enum_value| @enums_values << "'#{enum_value['value']}'" end "~randomize [#{@enums_values.join(', ')}]" else 'Custom Type' end end def value_after_namespace(string) string.split(':').last end # Based on WSDL type return a valid value # @param [String] type Type without the WSDL def fill_in_field_from_type(type) case type when 'string' options[:string_default] # 'test string' when 'int' 2 when 'boolean' true when 'double' '1.5' else try_enum_for type end end # @param [String, Symbol] underscore_separated Snakecase value to be converted to camel case def camel_case(underscore_separated) underscore_separated.to_s.split('_').collect(&:capitalize).join end # @param [Nokogiri::NodeSet] list List def wsdl_to_yaml_for(list) puts list list.each do |element| name = element['name'] type = value_after_namespace(element['type']) puts 'Name ' + name + ' type ' + type @use_camel_case = true if (/[[:upper:]]/.match(name[0]) != nil) @content += " #{name.snakecase}: #{fill_in_field_from_type(type)} # #{type} \n" # TODO: If details is a Hash need to loop again end end def ask_wsdl prompt = <<-EOF Enter WSDL: EOF print prompt.chop @wsdl = $stdin.gets.strip puts end def name_of_wsdl prompt = <<-EOF Enter what you would like to name WSDL (CamelCase): EOF print prompt.chop @name = $stdin.gets.strip puts end # Prompt user to enter basic auth details def enter_auth_details prompt = <<-EOF User Name: EOF print prompt.chop @auth_name = $stdin.gets.strip puts prompt = <<-EOF User Password: EOF print prompt.chop @auth_password = $stdin.gets.strip puts end end end