lhj-tools 0.1.71 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9994ca666916dfa43e3f9794e85cc6c2c6f0fad59cb7d17cd9ec39338e00ed4
4
- data.tar.gz: a77906cc7b4d42cc35a5e44164f37f0b2276894190d516788994bc8ce9511322
3
+ metadata.gz: ec999ed3fcb4f5fff34b2dc483b5932c77bfd34c59cee78dfcebd7ea1a10fc54
4
+ data.tar.gz: c0a438db4402ef344ddf83f3acd4f3bca228c9335aa8e8d240bab02ba4745269
5
5
  SHA512:
6
- metadata.gz: e1bab6ae3305c789e82664f918d8a22e1290ff4cd7fd16eb0b314816ceaf401b932f86164127b3f83cda4c11b97cb6c084fb8eac42da2918679d2ab82c81d737
7
- data.tar.gz: 74a00f584c2223ed1a726af3f284047a940dd8d5f02022bf98e2738350759ab0e16d807435281473a8be2c952fe0521390709ca01cf5094bfa50ccb28d7852a6
6
+ metadata.gz: 9201f7d556c51665acb83d63cbe4978eb6507d99d00b1da5ab92fa064557298242845fec4484d2cf327fc41a6bf1663c3648573627ecb3098338d5c591aa1d04
7
+ data.tar.gz: 217cc7ee797ee78ab6a074715bf346fc3e044779e2553a20a1b813a63239a3e72611d17e439477912415ba600325ed4f1d597446e213833c6146651419a22a67
@@ -11,12 +11,13 @@ module Lhj
11
11
  # generate model from yapi
12
12
  class Yapi < Command
13
13
  self.summary = '通过yapi接口生成请求'
14
- self.description = '更新 ~/.lhj/yapi.yml 文件配置后执行`lhj api`生成接口模型'
14
+ self.description = '执行`lhj api`生成接口模型'
15
15
 
16
16
  def self.options
17
17
  [
18
18
  %w[--id api的id],
19
19
  %w[--model-pre 模型的前缀],
20
+ %w[--model-name 模型的名称],
20
21
  %w[--save 保存生成文件]
21
22
  ]
22
23
  end
@@ -98,13 +99,14 @@ module Lhj
98
99
  end
99
100
 
100
101
  def save_to_file(service_code)
101
- file_name = gen_model_name('')
102
+ name = model_name
103
+ file_name = gen_model_name
102
104
  unless File.exist?(File.expand_path(sub_folder_name, '.'))
103
105
  FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.'))
104
106
  end
105
107
  h_file = File.join('.', sub_folder_name, "#{file_name}.h")
106
108
  m_file = File.join('.', sub_folder_name, "#{file_name}.m")
107
- service_file = File.join('.', sub_folder_name, "#{model_pre}#{model_name}Service.m")
109
+ service_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Service.m")
108
110
  File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive?
109
111
  File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
110
112
  File.write(service_file, service_code) if service_code
@@ -159,6 +161,10 @@ module Lhj
159
161
  @model_result_name || @config_model_name
160
162
  end
161
163
 
164
+ def req_model_name
165
+ 'Param'
166
+ end
167
+
162
168
  def model_suffix
163
169
  @config_model_suffix || @model_default_suffix
164
170
  end
@@ -225,7 +231,7 @@ module Lhj
225
231
  result = res_body['properties']['detailMsg']
226
232
  return unless result['type'] == 'object' || result['type'] == 'array'
227
233
 
228
- result['name'] = gen_model_name('')
234
+ result['name'] = gen_model_name
229
235
  result
230
236
  end
231
237
 
@@ -233,14 +239,18 @@ module Lhj
233
239
  return if !res_json || !res_json['data'] || !res_json['data']['req_body_other']
234
240
 
235
241
  result = JSON.parse(res_json['data']['req_body_other'])
236
- result['name'] = gen_model_name('')
242
+ result['name'] = gen_model_name(nil, :req)
237
243
  result
238
244
  end
239
245
 
240
- def gen_model_name(name)
241
- n = name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { Regexp.last_match(0).upcase }
242
- n = model_name if n.length <= 0
243
- "#{model_pre}#{n}#{model_suffix}"
246
+ def gen_model_name(property_name = nil, type = :res)
247
+ name = model_name
248
+ name = req_model_name if type == :req
249
+ unless property_name.nil?
250
+ name = property_name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { Regexp.last_match(0).upcase }
251
+ name = property_name.gsub(/^\w/) { Regexp.last_match(0).upcase } if name.length <= 0
252
+ end
253
+ "#{model_pre}#{name}#{model_suffix}"
244
254
  end
245
255
 
246
256
  def handle_model(model, &block)
@@ -395,7 +405,9 @@ module Lhj
395
405
  return unless data
396
406
 
397
407
  path = data['path']
398
- path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('') if path
408
+ if path
409
+ path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('')
410
+ end
399
411
  path_key = "k#{path_name}URL"
400
412
  mth = data['method']
401
413
  mth = 'JSON' if data['req_body_is_json_schema']
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.71"
5
+ VERSION = "0.1.73"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.71
4
+ version: 0.1.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian