rails-swagger 0.1.1 → 0.2.0

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
- SHA1:
3
- metadata.gz: 60dcbcd8c29a1f62409b5a74ada9fe10156d81d3
4
- data.tar.gz: 78f746f92e9e12c8b6bd8f5c1f2149d3a4efadfd
2
+ SHA256:
3
+ metadata.gz: d296e1d1dc96b987c238535613568bdc345e7b8c0fe9eb40559d7aafe6b059ae
4
+ data.tar.gz: 7e4304f36b6b494878e0a86938757f5cfdbdf811e2af9d1464b6f33a9844546c
5
5
  SHA512:
6
- metadata.gz: 35344fdc0cc7b480c0f30759657acce83f284b6a3e945be64bb1b4b6010501d0407ba2ed808603d89f0a9d8f724ec44ca9d8a7221b34086f75c7fbd28f7e7461
7
- data.tar.gz: 8734547b54976c568bcf36b14c953395943487d6e019a19567c7bbbe1dda14756879965068954110373536c9486462a69249bacda519aed5914fe62d527fb552
6
+ metadata.gz: c674eb007e4e5b247d97f86a976ef267f336b70a1c3de68425c42bff583c14f0f88c8f549ae821c66eac0c17435cea2112f2dae866e35372a24f8518b0328d09
7
+ data.tar.gz: 32037a7aaf48446df4c1aeef58d1103622304d4560e2aa22b01936caf3bc14fd0b86105e26bf9a96367a1aa0d9c2770747a8941b282655ecf37ce0dc3ee9adcd
@@ -3,6 +3,6 @@ require "rails/swagger/router"
3
3
  require "rails/swagger/engine"
4
4
 
5
5
  module Rails
6
- module Swagger
7
- end
6
+ module Swagger
7
+ end
8
8
  end
@@ -1,39 +1,43 @@
1
1
  module Rails
2
- module Swagger
3
- module Controller
4
-
5
- # METHODS_WITH_BODIES = [
6
- # :post,
7
- # :patch,
8
- # :put
9
- # ].freeze
10
-
11
- # Injects swagger-related code into the controller when included
12
- def self.included base
13
-
14
- # Add controller hooks
15
- # base.class_eval do
16
- # before_action :swagger_validate_params
17
- # end
18
-
19
- # Returns the swagger spec definition for the endpoint serving
20
- # the current request.
21
- def swagger_endpoint
22
- key = "#{params[:controller]}##{params[:action]}"
23
- swagger_engine.endpoints[key]
24
- end
25
-
26
- # Validates request parameters against the Swagger API spec
27
- # associated with this controller.
28
- # def swagger_validate_params
29
- # if METHODS_WITH_BODIES.include? request.method_symbol
30
- # body = request.POST
31
- # # TODO: add validation here
32
- # end
33
- # end
34
-
35
- end
36
-
37
- end
38
- end
2
+
3
+ module Swagger
4
+
5
+ module Controller
6
+
7
+ # METHODS_WITH_BODIES = [
8
+ # :post,
9
+ # :patch,
10
+ # :put
11
+ # ].freeze
12
+
13
+ # Injects swagger-related code into the controller when included
14
+ def self.included base
15
+
16
+ # Add controller hooks
17
+ # base.class_eval do
18
+ # before_action :swagger_validate_params
19
+ # end
20
+
21
+ # Returns the swagger spec definition for the endpoint serving
22
+ # the current request.
23
+ def swagger_endpoint
24
+ key = "#{params[:controller]}##{params[:action]}"
25
+ swagger_engine.endpoints[key]
26
+ end
27
+
28
+ # Validates request parameters against the Swagger API spec
29
+ # associated with this controller.
30
+ # def swagger_validate_params
31
+ # if METHODS_WITH_BODIES.include? request.method_symbol
32
+ # body = request.POST
33
+ # # TODO: add validation here
34
+ # end
35
+ # end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
39
43
  end
@@ -1,156 +1,158 @@
1
1
  module Rails
2
- module Swagger
3
-
4
- # Defines the Swagger spec file formats that are parsable by this gem.
5
- # Currently only the JSON format is supported.
6
- ALLOWED_FORMATS = [".json"].freeze
7
-
8
- # Defines a base class from which Swagger API engines can be created.
9
- # Uses namespace isolation to ensure routes don't conflict with any
10
- # pre-existing routes from the main rails application.
11
- class Engine < Rails::Engine
12
- isolate_namespace Rails::Swagger
13
- end
14
-
15
- # Helper method to create a new engine based on a module namespace
16
- # prefix and Swagger spec file. The engine ceated will be a subclass of
17
- # Rails::Swagger::Engine, which itself inherits from Rails::Engine.
18
- def self.Engine base_module, file
19
-
20
- # Convert the module prefix into a constant if passed in as a string
21
- base_module = Object.const_get base_module if String === base_module
22
-
23
- # Ensure the Swagger spec file is in an acceptable format
24
- ext = File.extname(file)
25
- unless ALLOWED_FORMATS.include? ext
26
- raise "Swagger files must end with #{ALLOWED_FORMATS.join(' or ')}. File given: #{file}"
27
- end
28
-
29
- # Attempt to read and parse the Swagger spec file
30
- document = File.read file
31
- case File.extname file
32
- when ".json"
33
- begin
34
- require 'json'
35
- document = JSON.parse document
36
- rescue JSON::ParserError
37
- raise $!, "Problem parsing swagger spec file \"#{file}\": #{$!.message.lines.first.strip}", $@
38
- end
39
- else
40
- raise "Swagger files must end with #{ALLOWED_FORMATS.join(' or ')}. File given: #{file}"
41
- end
42
-
43
- # Verify that the swagger version is supported
44
- unless document["swagger"] == "2.0"
45
- raise "Unsupported swagger version: #{document["swagger"]}. #{self} supports only version 2.0"
46
- end
47
-
48
- # Builds a routing tree based on the swagger spec file.
49
- # We'll add each endpoint to the routing tree and additionally
50
- # store it in an array to be used below.
51
- router = Router.new
52
- endpoints = []
53
- document["paths"].each do |url, actions|
54
- actions.each do |verb, definition|
55
- route = Endpoint.new(verb.downcase.to_sym, url, definition)
56
- router << route
57
- endpoints << route
58
- end
59
- end
60
-
61
- # Creates the engine that will be used to actually route the
62
- # contents of the swagger spec file. The engine will eventually be
63
- # attached to the base module (argument to this current method).
64
- #
65
- # Exposes `::router` and `::endpoints` methods to allow other parts
66
- # of the code to tie requests back to their spec file definitions.
67
- engine = Class.new Engine do
68
-
69
- @router = router
70
- @endpoints = Hash.new
71
- @schema = document
72
-
73
- class << self
74
- def router
75
- @router
76
- end
77
- def endpoints
78
- @endpoints
79
- end
80
- def schema
81
- @schema
82
- end
83
- end
84
-
85
- # Rack app for serving the original swagger file
86
- swagger_app = Class.new do
87
- def inspect
88
- "Rails::Swagger::Engine"
89
- end
90
- define_method :call do |env|
91
- [
92
- 200,
93
- {"Content-Type" => "application/json"},
94
- [engine.schema.to_json]
95
- ]
96
- end
97
- end
98
-
99
- # Adds routes to the engine by passing the Mapper to the top
100
- # of the routing tree. `self` inside the block refers to an
101
- # instance of `ActionDispatch::Routing::Mapper`.
102
- self.routes.draw do
103
- scope module: base_module.name.underscore, format: false do
104
- get "swagger.json", to: swagger_app.new
105
- router.draw self
106
- end
107
- end
108
-
109
- end
110
-
111
- # Assign the engine as a class on the base module
112
- base_module.const_set :Engine, engine
113
-
114
- # Creates a hash that maps routes back to their swagger spec file
115
- # equivalents. This is accomplished by mocking a request for each
116
- # swagger spec file endpoint and determining which controller and
117
- # action the request is routed to. Swagger spec file definitions
118
- # are then attached to that controller/action pair.
119
- endpoints.each do |route|
120
-
121
- # Mocks a request using the route's URL
122
- url = ::ActionDispatch::Journey::Router::Utils.normalize_path route.path
123
- env = ::Rack::MockRequest.env_for url, method: route[:method].upcase
124
- req = ::ActionDispatch::Request.new env
125
-
126
- # Maps the swagger spec endpoint to the destination controller
127
- # action by routing the request.
128
- mapped = engine.routes.router.recognize(req){}.first[1]
129
- key = "#{mapped[:controller]}##{mapped[:action]}"
130
- engine.endpoints[key] = route
131
-
132
- end
133
- engine.endpoints.freeze
134
-
135
- # Defines a helper module on the base module that can be used to
136
- # properly generate swagger-aware controllers. Any controllers
137
- # referenced from a swagger spec file should include this module.
138
- mod = Module.new do
139
- @base = base_module
140
- def self.included controller
141
- base_module = @base
142
- controller.include Controller
143
- define_method :swagger_engine do
144
- base_module.const_get :Engine
145
- end
146
- end
147
- end
148
- base_module.const_set :SwaggerController, mod
149
-
150
- # Returns the new engine
151
- base_module.const_get :Engine
152
-
153
- end
154
-
155
- end
2
+
3
+ module Swagger
4
+
5
+ # Defines the Swagger spec file formats that are parsable by this gem.
6
+ # Currently only the JSON format is supported.
7
+ ALLOWED_FORMATS = [".json"].freeze
8
+
9
+ # Defines a base class from which Swagger API engines can be created.
10
+ # Uses namespace isolation to ensure routes don't conflict with any
11
+ # pre-existing routes from the main rails application.
12
+ class Engine < Rails::Engine
13
+ isolate_namespace Rails::Swagger
14
+ end
15
+
16
+ # Helper method to create a new engine based on a module namespace
17
+ # prefix and Swagger spec file. The engine ceated will be a subclass of
18
+ # Rails::Swagger::Engine, which itself inherits from Rails::Engine.
19
+ def self.Engine base_module, file
20
+
21
+ # Convert the module prefix into a constant if passed in as a string
22
+ base_module = Object.const_get base_module if String === base_module
23
+
24
+ # Ensure the Swagger spec file is in an acceptable format
25
+ ext = File.extname(file)
26
+ unless ALLOWED_FORMATS.include? ext
27
+ raise "Swagger files must end with #{ALLOWED_FORMATS.join(' or ')}. File given: #{file}"
28
+ end
29
+
30
+ # Attempt to read and parse the Swagger spec file
31
+ document = File.read file
32
+ case File.extname file
33
+ when ".json"
34
+ begin
35
+ require 'json'
36
+ document = JSON.parse document
37
+ rescue JSON::ParserError
38
+ raise $!, "Problem parsing swagger spec file \"#{file}\": #{$!.message.lines.first.strip}", $@
39
+ end
40
+ else
41
+ raise "Swagger files must end with #{ALLOWED_FORMATS.join(' or ')}. File given: #{file}"
42
+ end
43
+
44
+ # Verify that the swagger version is supported
45
+ unless document["swagger"] == "2.0"
46
+ raise "Unsupported swagger version: #{document["swagger"]}. #{self} supports only version 2.0"
47
+ end
48
+
49
+ # Builds a routing tree based on the swagger spec file.
50
+ # We'll add each endpoint to the routing tree and additionally
51
+ # store it in an array to be used below.
52
+ router = Router.new
53
+ endpoints = []
54
+ document["paths"].each do |url, actions|
55
+ actions.each do |verb, definition|
56
+ route = Endpoint.new(verb.downcase.to_sym, url, definition)
57
+ router << route
58
+ endpoints << route
59
+ end
60
+ end
61
+
62
+ # Creates the engine that will be used to actually route the
63
+ # contents of the swagger spec file. The engine will eventually be
64
+ # attached to the base module (argument to this current method).
65
+ #
66
+ # Exposes `::router` and `::endpoints` methods to allow other parts
67
+ # of the code to tie requests back to their spec file definitions.
68
+ engine = Class.new Engine do
69
+
70
+ @router = router
71
+ @endpoints = Hash.new
72
+ @schema = document
73
+
74
+ class << self
75
+ def router
76
+ @router
77
+ end
78
+ def endpoints
79
+ @endpoints
80
+ end
81
+ def schema
82
+ @schema
83
+ end
84
+ end
85
+
86
+ # Rack app for serving the original swagger file
87
+ swagger_app = Class.new do
88
+ def inspect
89
+ "Rails::Swagger::Engine"
90
+ end
91
+ define_method :call do |env|
92
+ [
93
+ 200,
94
+ {"Content-Type" => "application/json"},
95
+ [engine.schema.to_json]
96
+ ]
97
+ end
98
+ end
99
+
100
+ # Adds routes to the engine by passing the Mapper to the top
101
+ # of the routing tree. `self` inside the block refers to an
102
+ # instance of `ActionDispatch::Routing::Mapper`.
103
+ self.routes.draw do
104
+ scope module: base_module.name.underscore, format: false do
105
+ get "swagger.json", to: swagger_app.new
106
+ router.draw self
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ # Assign the engine as a class on the base module
113
+ base_module.const_set :Engine, engine
114
+
115
+ # Creates a hash that maps routes back to their swagger spec file
116
+ # equivalents. This is accomplished by mocking a request for each
117
+ # swagger spec file endpoint and determining which controller and
118
+ # action the request is routed to. Swagger spec file definitions
119
+ # are then attached to that controller/action pair.
120
+ endpoints.each do |route|
121
+
122
+ # Mocks a request using the route's URL
123
+ url = ::ActionDispatch::Journey::Router::Utils.normalize_path route.path
124
+ env = ::Rack::MockRequest.env_for url, method: route[:method].upcase
125
+ req = ::ActionDispatch::Request.new env
126
+
127
+ # Maps the swagger spec endpoint to the destination controller
128
+ # action by routing the request.
129
+ mapped = engine.routes.router.recognize(req){}.first[1]
130
+ key = "#{mapped[:controller]}##{mapped[:action]}"
131
+ engine.endpoints[key] = route
132
+
133
+ end
134
+ engine.endpoints.freeze
135
+
136
+ # Defines a helper module on the base module that can be used to
137
+ # properly generate swagger-aware controllers. Any controllers
138
+ # referenced from a swagger spec file should include this module.
139
+ mod = Module.new do
140
+ @base = base_module
141
+ def self.included controller
142
+ base_module = @base
143
+ controller.include Controller
144
+ define_method :swagger_engine do
145
+ base_module.const_get :Engine
146
+ end
147
+ end
148
+ end
149
+ base_module.const_set :SwaggerController, mod
150
+
151
+ # Returns the new engine
152
+ base_module.const_get :Engine
153
+
154
+ end
155
+
156
+ end
157
+
156
158
  end
@@ -1,188 +1,195 @@
1
1
  module Rails
2
- module Swagger
3
-
4
- # Internally represents individual routes
5
- Endpoint = Struct.new(:method, :url, :definition, :_path) do
6
- def initialize *opts
7
- super
8
- self[:_path] = self.path
9
- end
10
- # Translates path params from {bracket} syntax to :symbol syntax
11
- def path
12
- self[:url].gsub(/\{(.+)\}/, ':\\1')
13
- end
14
- end
15
-
16
- # Defines RESTful routing conventions
17
- RESOURCE_ROUTES = {
18
- get: :index,
19
- post: :create
20
- }.freeze
21
- PARAM_ROUTES = {
22
- get: :show,
23
- patch: :update,
24
- put: :update,
25
- delete: :destroy
26
- }.freeze
27
-
28
- class Router
29
-
30
- attr_accessor :endpoints
31
-
32
- def initialize prefix = [], parent = nil
33
- @parent = parent
34
- @prefix = prefix.freeze
35
- @endpoints = []
36
- @subroutes = Hash.new do |hash, k|
37
- hash[k] = Router.new(@prefix + [k], self)
38
- end
39
- end
40
-
41
- # Adds an individual endpoint to the routing tree
42
- def << route
43
- raise "Argument must be an Endpoint" unless Endpoint === route
44
- _base, *subroute = route[:_path].split '/' # Split out first element
45
- if subroute.count == 0
46
- route[:_path] = ""
47
- @endpoints << route
48
- else
49
- route[:_path] = subroute.join '/'
50
- self[subroute[0]] << route
51
- end
52
- end
53
-
54
- # Returns a specific branch of the routing tree
55
- def [] path
56
- @subroutes[path]
57
- end
58
-
59
- # Returns the routing path
60
- def path
61
- "/" + @prefix.join("/")
62
- end
63
-
64
- # Returns the mode used for collecting routes
65
- def route_mode
66
- mode = :resource
67
- mode = :namespace if @endpoints.count == 0
68
- mode = :action if @subroutes.count == 0 && @parent && @parent.route_mode == :resource
69
- mode
70
- end
71
-
72
- # Returns the mode used for actions in this router
73
- def action_mode
74
- if /^:/ === @prefix[-2]
75
- :member
76
- elsif /^:/ === @prefix[-1]
77
- :param
78
- else
79
- :collection
80
- end
81
- end
82
-
83
- # Determines the action for a specific route
84
- def action_for route
85
- raise "Argument must be an Endpoint" unless Endpoint === route
86
- action = @prefix[-1]
87
- action = PARAM_ROUTES[route[:method]] if self.action_mode == :param
88
- action = RESOURCE_ROUTES[route[:method]] if self.route_mode == :resource && self.action_mode == :collection
89
- action
90
- end
91
-
92
- # Draws the routes for this router
93
- def draw map
94
- case self.route_mode
95
- when :resource
96
-
97
- # Find collection-level resource actions
98
- actions = @endpoints.map{ |r| self.action_for r }.select{ |a| Symbol === a }
99
-
100
- # Find parameter-level resource actions
101
- @subroutes.select{ |k, _| /^:/ === k }.values.each do |subroute|
102
- actions += subroute.endpoints.map{ |r| subroute.action_for r }.select{ |a| Symbol === a }
103
- end
104
-
105
- # Draw a resource
106
- map.resources @prefix.last.to_sym, only: actions do
107
- draw_actions! map
108
- draw_subroutes! map
109
- end
110
-
111
- when :namespace
112
-
113
- # Draw a namespace (unless at the top)
114
- if @prefix.join("/").blank?
115
- draw_subroutes! map
116
- else
117
- map.namespace @prefix.last do
118
- draw_subroutes! map
119
- end
120
- end
121
-
122
- when :action
123
-
124
- # Draw actions directly
125
- draw_actions! map
126
-
127
- end
128
-
129
- end
130
-
131
- # Returns the routing tree in text format
132
- def to_s
133
-
134
- output = ""
135
-
136
- path = "/" + @prefix.join('/')
137
- @endpoints.each do |route|
138
- output += "#{route[:method].to_s.upcase} #{path}\n"
139
- end
140
- @subroutes.each do |k, subroute|
141
- output += subroute.to_s
142
- end
143
-
144
- output
145
-
146
- end
147
-
148
- # Outputs a visual representation of the routing tree
149
- def _debug_routing_tree
150
2
 
151
- puts self.path + " - #{self.route_mode}"
152
- @endpoints.each do |route|
153
- puts "\t#{route[:method].to_s.upcase} to ##{self.action_for route} (#{self.action_mode})"
154
- end
155
- @subroutes.each do |k, subroute| subroute._debug_routing_tree end
3
+ module Swagger
4
+
5
+ # Internally represents individual routes
6
+ Endpoint = Struct.new(:method, :url, :definition, :_path) do
7
+ def initialize *opts
8
+ super
9
+ self[:_path] = self.path
10
+ end
11
+ # Translates path params from {bracket} syntax to :symbol syntax
12
+ def path
13
+ self[:url].gsub(/\{([^}]+)\}/, ':\\1')
14
+ end
15
+ end
16
+
17
+ # Defines RESTful routing conventions
18
+ RESOURCE_ROUTES = {
19
+ get: :index,
20
+ post: :create
21
+ }.freeze
22
+ PARAM_ROUTES = {
23
+ get: :show,
24
+ patch: :update,
25
+ put: :update,
26
+ delete: :destroy
27
+ }.freeze
28
+
29
+ class Router
30
+
31
+ attr_accessor :endpoints
32
+
33
+ def initialize prefix = [], parent = nil
34
+ @parent = parent
35
+ @prefix = prefix.freeze
36
+ @endpoints = []
37
+ @subroutes = Hash.new do |hash, k|
38
+ hash[k] = Router.new(@prefix + [k], self)
39
+ end
40
+ end
41
+
42
+ # Adds an individual endpoint to the routing tree
43
+ def << route
44
+ raise "Argument must be an Endpoint" unless Endpoint === route
45
+ _base, *subroute = route[:_path].split '/' # Split out first element
46
+ if subroute.count == 0
47
+ route[:_path] = ""
48
+ @endpoints << route
49
+ else
50
+ route[:_path] = subroute.join '/'
51
+ self[subroute[0]] << route
52
+ end
53
+ end
54
+
55
+ # Returns a specific branch of the routing tree
56
+ def [] path
57
+ @subroutes[path]
58
+ end
59
+
60
+ # Returns the routing path
61
+ def path
62
+ "/" + @prefix.join("/")
63
+ end
64
+
65
+ # Returns the mode used for collecting routes
66
+ def route_mode
67
+ mode = :resource
68
+ mode = :namespace if @endpoints.count == 0
69
+ mode = :action if @subroutes.count == 0 && @parent && @parent.route_mode == :resource
70
+ mode = :param if /^:/ === @prefix.last
71
+ mode
72
+ end
73
+
74
+ # Returns the mode used for actions in this router
75
+ def action_mode
76
+ if /^:/ === @prefix[-1]
77
+ :param
78
+ else
79
+ :collection
80
+ end
81
+ end
82
+
83
+ # Determines the action for a specific route
84
+ def action_for route
85
+ raise "Argument must be an Endpoint" unless Endpoint === route
86
+ action = @prefix[-1]
87
+ action = PARAM_ROUTES[route[:method]] if self.action_mode == :param
88
+ action = RESOURCE_ROUTES[route[:method]] if self.route_mode == :resource && self.action_mode == :collection
89
+ action
90
+ end
91
+
92
+ # Draws the routes for this router
93
+ def draw map
94
+
95
+ case self.route_mode
96
+ when :resource
97
+
98
+ # Find collection-level resource actions
99
+ actions = @endpoints.map{ |r| self.action_for r }.select{ |a| Symbol === a }
100
+
101
+ # Find parameter-level resource actions
102
+ @subroutes.select{ |k, _| /^:/ === k }.values.each do |subroute|
103
+ actions += subroute.endpoints.map{ |r| subroute.action_for r }.select{ |a| Symbol === a }
104
+ end
105
+
106
+ # Draw a resource
107
+ map.resources @prefix.last.to_sym, only: actions do
108
+ draw_actions! map
109
+ draw_subroutes! map
110
+ end
111
+
112
+ when :namespace
113
+
114
+ # Draw a namespace (unless at the top)
115
+ if @prefix.join("/").blank?
116
+ draw_subroutes! map
117
+ else
118
+ map.namespace @prefix.last do
119
+ draw_subroutes! map
120
+ end
121
+ end
122
+
123
+ when :param
156
124
 
157
- end
125
+ # Draw subroutes directly
126
+ draw_subroutes! map
158
127
 
159
- protected
128
+ when :action
160
129
 
161
- def draw_actions! map
130
+ # Draw actions directly
131
+ draw_actions! map
162
132
 
163
- @endpoints.each do |route|
133
+ end
134
+
135
+ end
164
136
 
165
- # Params hash for the route to be added
166
- params = Hash.new
167
- params[:via] = route[:method]
168
- params[:on] = self.action_mode unless self.action_mode == :param
169
- params[:action] = self.action_for route
137
+ # Returns the routing tree in text format
138
+ def to_s
170
139
 
171
- # These are handled in the resource
172
- next if Symbol === params[:action]
140
+ output = ""
173
141
 
174
- # Add this individual route
175
- map.match @prefix.last, params
142
+ path = "/" + @prefix.join('/')
143
+ @endpoints.each do |route|
144
+ output += "#{route[:method].to_s.upcase} #{path}\n"
145
+ end
146
+ @subroutes.each do |k, subroute|
147
+ output += subroute.to_s
148
+ end
176
149
 
177
- end
150
+ output
178
151
 
179
- end
152
+ end
180
153
 
181
- def draw_subroutes! map
182
- @subroutes.values.each { |r| r.draw map }
183
- end
154
+ # Outputs a visual representation of the routing tree
155
+ def _debug_routing_tree
184
156
 
185
- end
157
+ puts self.path + " - #{self.route_mode}"
158
+ @endpoints.each do |route|
159
+ puts "\t#{route[:method].to_s.upcase} to ##{self.action_for route} (#{self.action_mode})"
160
+ end
161
+ @subroutes.each do |k, subroute| subroute._debug_routing_tree end
162
+
163
+ end
164
+
165
+ protected
166
+
167
+ def draw_actions! map
168
+
169
+ @endpoints.each do |route|
170
+
171
+ # Params hash for the route to be added
172
+ params = Hash.new
173
+ params[:via] = route[:method]
174
+ params[:on] = self.action_mode unless self.action_mode == :param
175
+ params[:action] = self.action_for route
176
+
177
+ # These are handled in the resource
178
+ next if Symbol === params[:action]
179
+
180
+ # Add this individual route
181
+ map.match @prefix.last, params
182
+
183
+ end
184
+
185
+ end
186
+
187
+ def draw_subroutes! map
188
+ @subroutes.values.each { |r| r.draw map }
189
+ end
190
+
191
+ end
192
+
193
+ end
186
194
 
187
- end
188
195
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenaniah Cerny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-29 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.6.8
100
+ rubygems_version: 3.0.1
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: Turns Swagger API schemas into mountable Rails engines