rails-swagger 0.1.0 → 0.4.0

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
- SHA1:
3
- metadata.gz: 8b89c6bd9042fab14f38e6fd3521e3fa12a33490
4
- data.tar.gz: fd06df4097b8b28ffb1b25f7eb70fb9a39adeab3
2
+ SHA256:
3
+ metadata.gz: 462fb2b6ed49fc0de9bbf5542f0d71932ab5b469f3b9734bea7bd2d542ceae70
4
+ data.tar.gz: f6422820a1a13d6973ddc71e8d903bee18058883bfd2bb9d2df147d511acacfe
5
5
  SHA512:
6
- metadata.gz: 75d982c6a1d3813c9d3ffb413314305f1bfc8626ea63d218df0c8e0c57a6d03e921dfea64f2f9d2b007f56f561773f9c5cf217ec7544ee054a595240005ae754
7
- data.tar.gz: 0f4da4227fb7fac70c09d58804e009182ed4faa6503eeae552a13eb85a5f68fd2181654d22a5fdeb766d6962c1d6b5619d9d987ddd98b91f9dc3ce28042cbe99
6
+ metadata.gz: fb82c2935ea4b28614689a94f1861d0477c77281f53fe39222bc51ce9b0ab102ecec418ef6f3ad4b6292dd77c15da3ed382c4809ebe0c6c4450d8e5b5782eaa4
7
+ data.tar.gz: f616ceb7ffafc3feb4ebc5e935fdb0a153c724e93e8da0497ea9592f0e8afc249d50eacdf3b4b06d70f0748a3ed89092f8a96ad95fdef207ee7301e74aeea710
@@ -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
- endpoint = 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,196 @@
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
124
+
125
+ # Draw subroutes directly
126
+ draw_subroutes! map
127
+ draw_actions! map
156
128
 
157
- end
129
+ when :action
158
130
 
159
- protected
131
+ # Draw actions directly
132
+ draw_actions! map
133
+
134
+ end
135
+
136
+ end
160
137
 
161
- def draw_actions! map
138
+ # Returns the routing tree in text format
139
+ def to_s
162
140
 
163
- @endpoints.each do |route|
141
+ output = ""
164
142
 
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
143
+ path = "/" + @prefix.join('/')
144
+ @endpoints.each do |route|
145
+ output += "#{route[:method].to_s.upcase} #{path}\n"
146
+ end
147
+ @subroutes.each do |k, subroute|
148
+ output += subroute.to_s
149
+ end
170
150
 
171
- # These are handled in the resource
172
- next if Symbol === params[:action]
151
+ output
173
152
 
174
- # Add this individual route
175
- map.match @prefix.last, params
153
+ end
176
154
 
177
- end
155
+ # Outputs a visual representation of the routing tree
156
+ def _debug_routing_tree
178
157
 
179
- end
158
+ puts self.path + " - #{self.route_mode}"
159
+ @endpoints.each do |route|
160
+ puts "\t#{route[:method].to_s.upcase} to ##{self.action_for route} (#{self.action_mode})"
161
+ end
162
+ @subroutes.each do |k, subroute| subroute._debug_routing_tree end
180
163
 
181
- def draw_subroutes! map
182
- @subroutes.values.each { |r| r.draw map }
183
- end
164
+ end
184
165
 
185
- end
166
+ protected
167
+
168
+ def draw_actions! map
169
+
170
+ @endpoints.each do |route|
171
+
172
+ # Params hash for the route to be added
173
+ params = Hash.new
174
+ params[:via] = route[:method]
175
+ params[:on] = self.action_mode unless self.action_mode == :param
176
+ params[:action] = self.action_for route
177
+
178
+ # These are handled in the resource
179
+ next if Symbol === params[:action]
180
+
181
+ # Add this individual route
182
+ map.match @prefix.last, params
183
+
184
+ end
185
+
186
+ end
187
+
188
+ def draw_subroutes! map
189
+ @subroutes.values.each { |r| r.draw map }
190
+ end
191
+
192
+ end
193
+
194
+ end
186
195
 
187
- end
188
196
  end
data/lib/rails/swagger.rb CHANGED
@@ -1,9 +1,8 @@
1
- require "json-schema"
2
1
  require "rails/swagger/controller"
3
2
  require "rails/swagger/router"
4
3
  require "rails/swagger/engine"
5
4
 
6
5
  module Rails
7
- module Swagger
8
- end
6
+ module Swagger
7
+ end
9
8
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.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-05-17 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json-schema
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -111,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
97
  - !ruby/object:Gem::Version
112
98
  version: '0'
113
99
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.8
100
+ rubygems_version: 3.1.2
116
101
  signing_key:
117
102
  specification_version: 4
118
103
  summary: Turns Swagger API schemas into mountable Rails engines