lib/lhj/command/yapi.rb in lhj-tools-0.1.69 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.70

- old
+ new

@@ -22,24 +22,24 @@ end def initialize(argv) @id = argv.option('id') @model_pre_name = argv.option('model-pre') + @model_result_name = argv.option('model-name') @language = argv.option('lan', 'oc') @save = argv.flag?('save', false) @sync = argv.flag?('sync', false) @notify = argv.flag?('notify', false) @debug = argv.flag?('debug', false) @sync = true if @notify @save = true if @sync @http_headers = [] @config_id = '' @config_model_pre = 'ML' + @config_model_name = 'Result' @model_default_suffix = 'Model' @type_trans = {} - @config_model_names = [] - @model_names = [] @http_url = '' super end def handle @@ -96,19 +96,17 @@ @sub_folder_name ||= time.strftime('%Y%m%d%H%M%S') @sub_folder_name end def save_to_file(service_code) - @model_names = [] - model_name = @config_model_names.first 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") - service_file = File.join('.', sub_folder_name, "#{model_pre}#{model_name}Service.m") + h_file = File.join('.', api_id, sub_folder_name, "#{file_name}.h") + m_file = File.join('.', api_id, sub_folder_name, "#{file_name}.m") + service_file = File.join('.', api_id, sub_folder_name, "#{model_pre}#{model_name}Service.m") File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive? File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive? File.write(service_file, service_code) if service_code puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green { h_file: h_file, m_file: m_file, s_file: service_file } @@ -143,11 +141,11 @@ end @http_url = config['url'] @config_id = config['id'] @config_model_pre = config['model_pre'] @config_model_suffix = config['model_suffix'] - @config_model_names = config['model_names'] + @config_model_name = config['model_name'] @type_trans = config['type_trans'] end def api_id @id || @config_id.to_s @@ -155,10 +153,14 @@ def model_pre @model_pre_name || @config_model_pre end + def model_name + @model_result_name || @config_model_name + end + def model_suffix @config_model_suffix || @model_default_suffix end def req_api_model @@ -234,17 +236,13 @@ result['name'] = gen_model_name('') result end def gen_model_name(name) - n = name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { $&.upcase } - if n.length <= 0 - n = @config_model_names.detect { |c| @model_names.none? { |na| na.gsub(/#{model_pre}(.*)Model/, '\1').eql?(c) } } - end - model_name = "#{model_pre}#{n}#{model_suffix}" - @model_names << model_name - model_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}" end def handle_model(model, &block) p_type = model['type'] p_name = model['name'] @@ -395,10 +393,10 @@ 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/) { $&.upcase } }.join('') if path + path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('') if path path_key = "k#{path_name}URL" mth = data['method'] mth = 'JSON' if data['req_body_is_json_schema'] case @language when 'oc'