lib/lhj/command/yapi.rb in lhj-tools-0.1.77 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.79

- old
+ new

@@ -174,10 +174,11 @@ @config_model_pre = config['model_pre'] @config_model_suffix = config['model_suffix'] @config_model_name = config['model_name'] @config_robot_url = config['dingtalk'] @type_trans = config['type_trans'] + @config_property_mapper = config['property_mapper'] end def api_id @id || @config_id.to_s end @@ -200,10 +201,14 @@ def robot_url @config_robot_url || 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807' end + def property_mapper + @config_property_mapper || { 'id' => 'gid' } + end + def get_interface_api_model uri = URI.parse(interface_url_str) req = Net::HTTP::Get.new(uri) req['Cookie'] = @http_headers.join('; ') res = Net::HTTP.start(uri.hostname, uri.port) do |http| @@ -363,16 +368,26 @@ if str&.length&.positive? puts_m '+(NSDictionary *)modelContainerPropertyGenericClass {' puts_m " return @{#{str}};" puts_m '}' end + properties = model[:properties].filter { |p| property_mapper.keys.include?(p[:key]) }.map do |p| + "@\"#{property_mapper[p[:key]]}\": @\"#{p[:key]}\"" + end + property_mapper_str = properties.join(', ') if properties.count.positive? + if property_mapper_str&.length&.positive? + puts_m '+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {' + puts_m " return @{#{property_mapper_str}};" + puts_m '}' + end puts_m "@end\n" puts "\n\n" end end def print_model(m) key = m[:key] + key = property_mapper[key] if property_mapper.keys.include?(key) type_name = m[:type_name] type = m[:type] des = m[:description] || '' des.gsub!(/\n/, ' ') default = m[:default]