swaggard 1.0.1 → 1.0.2
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/swaggard.rb +21 -14
- data/lib/swaggard/parsers/controller.rb +11 -5
- data/lib/swaggard/swagger/operation.rb +1 -1
- data/lib/swaggard/swagger/tag.rb +5 -6
- data/lib/swaggard/version.rb +1 -1
- 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: 7a8b23d0506bee9f1348d9d9226395143d49fddafdfedd0b738e6fa46e037034
|
4
|
+
data.tar.gz: d217e3ea082ecb262f8a298d8c3418835441a0d6c3e67737cf2affb14d7a90f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c27ee9ce529d840cf54f0e9c3fa3849c9cac9c6a42f99d2b46ff7330865e48a3a7890473455b8925f5c907f569f0c36d4bb904ae501a586207ed670a9fbca934
|
7
|
+
data.tar.gz: f1fd82efe8b1106596a48470dcb7bc2a528e7e27340c1f046c986b281ab615cd92a779362f620a54ed5af429bd3b6957df8bbfd7f82d6ece3bb8de9c2d8ecfb7
|
data/lib/swaggard.rb
CHANGED
@@ -61,21 +61,25 @@ module Swaggard
|
|
61
61
|
@api.ignore_put_if_patch! if Swaggard.configuration.ignore_put_if_patch_exists
|
62
62
|
end
|
63
63
|
|
64
|
+
def tag_matches?(tag, controller_name, path)
|
65
|
+
matches = tag.controller_name == controller_name
|
66
|
+
|
67
|
+
return matches unless tag.route.present?
|
68
|
+
|
69
|
+
matches && Regexp.new(tag.route).match?(path)
|
70
|
+
end
|
71
|
+
|
64
72
|
def build_operation(path, verb, route)
|
65
73
|
controller_name = route[:controller]
|
66
74
|
action_name = route[:action]
|
67
75
|
|
68
|
-
|
69
|
-
|
70
|
-
controller_tag = controllers[controller_name][:tag]
|
76
|
+
controller_tag, controller_operations = tags.find { |tag, _operations| tag_matches?(tag, controller_name, path) }
|
71
77
|
|
72
78
|
return unless controller_tag
|
73
79
|
|
74
|
-
return unless
|
75
|
-
|
76
|
-
return unless controllers[controller_name][:operations][action_name]
|
80
|
+
return unless controller_operations[action_name]
|
77
81
|
|
78
|
-
operation_yard_object =
|
82
|
+
operation_yard_object = controller_operations[action_name]
|
79
83
|
|
80
84
|
return unless operation_yard_object
|
81
85
|
|
@@ -100,23 +104,26 @@ module Swaggard
|
|
100
104
|
end
|
101
105
|
end
|
102
106
|
|
103
|
-
def
|
104
|
-
return @
|
107
|
+
def tags
|
108
|
+
return @tags if @tags
|
105
109
|
|
106
110
|
parser = Parsers::Controller.new
|
107
111
|
|
108
|
-
@
|
112
|
+
@tags = []
|
109
113
|
Dir[configuration.controllers_path].each do |file|
|
110
114
|
yard_objects = get_yard_objects(file)
|
111
115
|
|
112
|
-
|
116
|
+
tags, operations = parser.run(yard_objects)
|
113
117
|
|
114
|
-
next unless
|
118
|
+
next unless tags
|
115
119
|
|
116
|
-
|
120
|
+
tags.each do |tag|
|
121
|
+
@tags << [tag, operations]
|
122
|
+
# [tag.controller_class.controller_path] ||= { tag: tag, operations: operations }
|
123
|
+
end
|
117
124
|
end
|
118
125
|
|
119
|
-
@
|
126
|
+
@tags
|
120
127
|
end
|
121
128
|
|
122
129
|
def routes
|
@@ -4,23 +4,29 @@ require_relative '../swagger/tag'
|
|
4
4
|
module Swaggard
|
5
5
|
module Parsers
|
6
6
|
class Controller
|
7
|
-
|
8
7
|
def run(yard_objects)
|
9
|
-
|
8
|
+
tags = nil
|
10
9
|
operations = {}
|
11
10
|
|
12
11
|
yard_objects.each do |yard_object|
|
13
12
|
if yard_object.type == :class
|
14
|
-
|
15
|
-
elsif
|
13
|
+
tags = get_tags(yard_object)
|
14
|
+
elsif tags && yard_object.type == :method
|
16
15
|
name = yard_object.name
|
17
16
|
operations[name.to_s] = yard_object
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
return
|
20
|
+
return tags, operations
|
22
21
|
end
|
23
22
|
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_tags(yard_object)
|
26
|
+
tags = yard_object.tags.select { |tag| tag.tag_name == 'tag' }
|
27
|
+
|
28
|
+
tags.map { |tag| Swagger::Tag.new(yard_object, tag) }
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/swaggard/swagger/tag.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module Swaggard
|
2
2
|
module Swagger
|
3
3
|
class Tag
|
4
|
-
|
5
4
|
attr_accessor :name, :description
|
6
5
|
|
7
|
-
attr_reader :controller_class
|
6
|
+
attr_reader :controller_class, :controller_name, :route
|
8
7
|
|
9
|
-
def initialize(yard_object)
|
8
|
+
def initialize(yard_object, tag)
|
10
9
|
controller_name = "#{yard_object.namespace}::#{yard_object.name}"
|
11
10
|
|
12
11
|
@yard_name = yard_object.name
|
13
12
|
@controller_class = controller_name.constantize
|
14
|
-
|
15
|
-
tag = yard_object.tags.find { |tag| tag.tag_name == 'tag' }
|
13
|
+
@controller_name = controller_class.controller_path
|
16
14
|
|
17
15
|
@name = tag ? tag.text : "#{@controller_class.controller_path}"
|
16
|
+
@name, @route = @name.split(' ')
|
17
|
+
|
18
18
|
@description = yard_object.docstring || ''
|
19
19
|
end
|
20
20
|
|
@@ -24,7 +24,6 @@ module Swaggard
|
|
24
24
|
'description' => @description
|
25
25
|
}
|
26
26
|
end
|
27
|
-
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/lib/swaggard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swaggard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|