lib/lhj/command/yapi.rb in lhj-tools-0.1.72 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.73

- old
+ new

@@ -64,11 +64,10 @@ print_req_query(res_body['data']) # 4.print request method service_code = print_http_method(res_body['data'], result_model_name, param_model_name) # 5.save to file file_map = save_to_file(service_code) if @save - puts file_map # 6.push to git push_to_git if @sync # 7.notify robot notify_robot(file_map) if @notify end @@ -99,11 +98,11 @@ @sub_folder_name end def save_to_file(service_code) name = model_name - file_name = gen_model_name('') + file_name = gen_model_name unless File.exist?(File.expand_path(sub_folder_name, '.')) FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.')) end h_file = File.join('.', sub_folder_name, "#{file_name}.h") m_file = File.join('.', sub_folder_name, "#{file_name}.m") @@ -160,10 +159,14 @@ def model_name @model_result_name || @config_model_name end + def req_model_name + 'Param' + end + def model_suffix @config_model_suffix || @model_default_suffix end def req_api_model @@ -226,26 +229,30 @@ return if !res_body['properties'] || !res_body['properties']['detailMsg'] result = res_body['properties']['detailMsg'] return unless result['type'] == 'object' || result['type'] == 'array' - result['name'] = gen_model_name('') + result['name'] = gen_model_name result end def fetch_req_body(res_json) return if !res_json || !res_json['data'] || !res_json['data']['req_body_other'] result = JSON.parse(res_json['data']['req_body_other']) - result['name'] = gen_model_name('') + result['name'] = gen_model_name(nil, :req) result end - def gen_model_name(name) - n = name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { Regexp.last_match(0).upcase } - n = model_name if n.length <= 0 - "#{model_pre}#{n}#{model_suffix}" + def gen_model_name(property_name = nil, type = :res) + name = model_name + name = req_model_name if type == :req + unless property_name.nil? + name = property_name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { Regexp.last_match(0).upcase } + name = property_name.gsub(/^\w/) { Regexp.last_match(0).upcase } if name.length <= 0 + end + "#{model_pre}#{name}#{model_suffix}" end def handle_model(model, &block) p_type = model['type'] p_name = model['name'] @@ -396,10 +403,12 @@ def print_http_method(data, result_model_name, param_model_name) return unless data path = data['path'] - path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('') if path + if path + path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('') + end path_key = "k#{path_name}URL" mth = data['method'] mth = 'JSON' if data['req_body_is_json_schema'] case @language when 'oc'