swaggard 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3e1aa159808f0d01c9e6759727b97aff8a0cb4c383f441a3ca602e6b302da8b
4
- data.tar.gz: 4f3b2511fbd15049e5e8746af31174705544a477b70cc0cbbe30d24563897ee7
3
+ metadata.gz: 7a8b23d0506bee9f1348d9d9226395143d49fddafdfedd0b738e6fa46e037034
4
+ data.tar.gz: d217e3ea082ecb262f8a298d8c3418835441a0d6c3e67737cf2affb14d7a90f2
5
5
  SHA512:
6
- metadata.gz: 244da8fb5d6d234aab95d0b6e1b6bf13fd1dd7f519daf93aa2ff1f21dd05e2d0a886aa1e80f07ae7181d7541fc853b83bf5f711465976577cea725175bb0be36
7
- data.tar.gz: c82e666367b0555c8d7de02f785c9045aa53c77c591855afa5e1c093f294c8b69cff7cbcc5a9eb70cdda1004f855cf149148fede20be4f4296515878855aa34c
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
- return unless controllers[controller_name]
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 controllers[controller_name][:operations]
75
-
76
- return unless controllers[controller_name][:operations][action_name]
80
+ return unless controller_operations[action_name]
77
81
 
78
- operation_yard_object = controllers[controller_name][:operations][action_name]
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 controllers
104
- return @controllers if @controllers
107
+ def tags
108
+ return @tags if @tags
105
109
 
106
110
  parser = Parsers::Controller.new
107
111
 
108
- @controllers = {}
112
+ @tags = []
109
113
  Dir[configuration.controllers_path].each do |file|
110
114
  yard_objects = get_yard_objects(file)
111
115
 
112
- tag, operations = parser.run(yard_objects)
116
+ tags, operations = parser.run(yard_objects)
113
117
 
114
- next unless tag
118
+ next unless tags
115
119
 
116
- @controllers[tag.controller_class.controller_path] ||= { tag: tag, operations: operations }
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
- @controllers
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
- tag = nil
8
+ tags = nil
10
9
  operations = {}
11
10
 
12
11
  yard_objects.each do |yard_object|
13
12
  if yard_object.type == :class
14
- tag = Swagger::Tag.new(yard_object)
15
- elsif tag && yard_object.type == :method
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 tag, operations
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
@@ -32,7 +32,7 @@ module Swaggard
32
32
 
33
33
  case yard_tag.tag_name
34
34
  when 'operation_id'
35
- @operation_id = value
35
+ @operation_id = "#{@tag.name}.#{value}"
36
36
  when 'query_parameter'
37
37
  @parameters << Parameters::Query.new(value)
38
38
  when 'form_parameter'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Swaggard
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
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.1
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-07-31 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails