acts_as_doc 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/acts_as_doc.gemspec +1 -1
- data/lib/acts_as_doc/response_parser.rb +36 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84a468753835af1c1f73d8edf468234bd164283c67b18a0f1a4281bea905fc86
|
4
|
+
data.tar.gz: 498222082962d5a7376994cdde490ea64d03440a1a1487b568a9fc9cad6c0d38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7965992ef4dc0b7464b1742a261a668d1793343bee96d876d3b9771328d54dc97740db4df2fafe9f2b8848c2eed7e45d931503e6c19a896a846cbfc5cb2e4e16
|
7
|
+
data.tar.gz: 951e8fc0ac3c327979e8bf2d53c32dcaef6fda75aafb3b7e4e2815695ff72261feda7234ec64f40ee99234156194f5a1973cb8cd141dcdc4879c69cec0d06821
|
data/acts_as_doc.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# rubocop:disable all
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "acts_as_doc"
|
4
|
-
s.version = "1.0
|
4
|
+
s.version = "1.1.0"
|
5
5
|
s.summary = "Generate swagger response doc"
|
6
6
|
s.description = "Add swagger comment to any ruby file for generating swagger response doc struct"
|
7
7
|
s.authors = ["alex.zang"]
|
@@ -16,6 +16,17 @@ module ActsAsDoc
|
|
16
16
|
|
17
17
|
REF_FLAG = '$'
|
18
18
|
|
19
|
+
TYPE_MAPPER = {
|
20
|
+
integer: 'integer',
|
21
|
+
string: 'string',
|
22
|
+
decimal: 'number',
|
23
|
+
text: 'string',
|
24
|
+
geography: 'string',
|
25
|
+
json: 'object',
|
26
|
+
jsonb: 'object',
|
27
|
+
array: 'array'
|
28
|
+
}.freeze
|
29
|
+
|
19
30
|
# 处理注释
|
20
31
|
#
|
21
32
|
# @param token [String] one line of comments
|
@@ -25,24 +36,36 @@ module ActsAsDoc
|
|
25
36
|
end
|
26
37
|
|
27
38
|
# Make props recursion
|
39
|
+
#
|
28
40
|
# @example
|
29
41
|
# >> ActsAsDoc::ResponseParser.props_recursion!({}, '$a.$b.c', 'c', 'd')
|
30
42
|
# # => {'a' => }
|
31
43
|
#
|
32
44
|
# @return [Hash] 处理过的hash
|
33
45
|
# rubocop:disable all
|
34
|
-
def self.props_recursion!(hash, name, type, desc)
|
46
|
+
def self.props_recursion!(hash, name, type, desc = '', klass = nil)
|
35
47
|
arr = name.split('.')
|
36
48
|
name = arr.shift.sub(/^\$/, '')
|
37
49
|
|
38
50
|
hash[name] = {} unless hash.key?(name)
|
39
51
|
|
40
52
|
if arr.empty?
|
41
|
-
|
53
|
+
if klass && (matches = desc.match(/^\(([a-zA-Z]+)\)$/))
|
54
|
+
columns = Object.const_get(klass).columns.map do |column|
|
55
|
+
[ column.name.to_s, [TYPE_MAPPER[column.type], column.comment] ]
|
56
|
+
end.to_h
|
57
|
+
|
58
|
+
matches[1].split(',').each do |attr_name|
|
59
|
+
c_type, c_desc = columns[attr_name]
|
60
|
+
self.props_recursion!(hash, "$#{name}.#{attr_name}", c_type, c_desc)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
hash[name].merge!(type: type, description: desc)
|
64
|
+
end
|
42
65
|
else
|
43
66
|
nest_hash = hash[name]
|
44
67
|
nest_hash[:properties] = {} unless nest_hash.key?(:properties)
|
45
|
-
self.props_recursion!(nest_hash[:properties], arr.join('.'), type, desc)
|
68
|
+
self.props_recursion!(nest_hash[:properties], arr.join('.'), type, desc, klass)
|
46
69
|
end
|
47
70
|
|
48
71
|
hash
|
@@ -62,16 +85,24 @@ module ActsAsDoc
|
|
62
85
|
|
63
86
|
if tag == '@prop'
|
64
87
|
desc = arr[3..] ? arr[3..].join(' ') : ''
|
65
|
-
|
88
|
+
|
89
|
+
matches = type.match(/\[(?<type>[a-zA-Z<>]+)\]/)
|
66
90
|
type = matches ? matches[:type] : 'string'
|
67
91
|
|
92
|
+
klass_matches = type.match(/(?<type>[a-zA-Z]+)<(?<klass>[a-zA-Z]+)>/)
|
93
|
+
klass = nil
|
94
|
+
if klass_matches
|
95
|
+
type = SUPPORT_TYPES.include?(klass_matches[:type]) ? klass_matches[:type] : 'string'
|
96
|
+
klass = klass_matches[:klass]
|
97
|
+
end
|
98
|
+
|
68
99
|
if name.start_with?(':')
|
69
100
|
name = name.sub(/^:/, '')
|
70
101
|
schema[name] = { type: type, description: desc }
|
71
102
|
end
|
72
103
|
|
73
104
|
if name.start_with?(REF_FLAG)
|
74
|
-
self.class.props_recursion!(schema, name, type, desc)
|
105
|
+
self.class.props_recursion!(schema, name, type, desc, klass)
|
75
106
|
end
|
76
107
|
end
|
77
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alex.zang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Add swagger comment to any ruby file for generating swagger response
|
14
14
|
doc struct
|