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 +4 -4
- data/lib/lhj/command/yapi.rb +22 -10
- data/lib/lhj/tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec999ed3fcb4f5fff34b2dc483b5932c77bfd34c59cee78dfcebd7ea1a10fc54
|
|
4
|
+
data.tar.gz: c0a438db4402ef344ddf83f3acd4f3bca228c9335aa8e8d240bab02ba4745269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9201f7d556c51665acb83d63cbe4978eb6507d99d00b1da5ab92fa064557298242845fec4484d2cf327fc41a6bf1663c3648573627ecb3098338d5c591aa1d04
|
|
7
|
+
data.tar.gz: 217cc7ee797ee78ab6a074715bf346fc3e044779e2553a20a1b813a63239a3e72611d17e439477912415ba600325ed4f1d597446e213833c6146651419a22a67
|
data/lib/lhj/command/yapi.rb
CHANGED
|
@@ -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 = '
|
|
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
|
-
|
|
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}#{
|
|
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(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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']
|
data/lib/lhj/tools/version.rb
CHANGED