jsonapi_swagger_helpers 0.4.1 → 0.4.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
  SHA1:
3
- metadata.gz: 03480867e028891240da97dd56570e73c9919261
4
- data.tar.gz: 017a21e1b94a18e467fd669623af883f36b7ae39
3
+ metadata.gz: 3ae4cfb11abca237e55783d3638b67e6a163a9bc
4
+ data.tar.gz: 5b3c47fe4d0709438891357a1dfb2fe3c41955fd
5
5
  SHA512:
6
- metadata.gz: a959fd5046fff648b6b82db8e407d5393bd2c88fb58d2b451a58e22adaaf28b8955e848b9482c3148fddfb6334320f155ea097cd49a1095c6149fd54f87efb17
7
- data.tar.gz: 24f553e718e0dcf36142cbffa4ef90f215b767dffdca739d63f152162b2d923700362f3de51f3168291ef4a232ff417a5705dd6f44136e18b79a2c99ed2c4e5a
6
+ metadata.gz: 2ac4c4df5cccd5f90a6e24f63df634f65f5570549f991790ec628fd540be531070534623481034976ef6dc3df27a3f87d839f38f8d7378484a5950b9d8b9b08d
7
+ data.tar.gz: 34a3b055667e5049143676800995a18e26a073bf9f9abd30fb86c1592f0cbf75749c67daacee9a0e214c1c6fdd558e7c53077271db7b91220e7b6a36a287dc7b
@@ -22,10 +22,26 @@ module JsonapiSwaggerHelpers
22
22
  JsonapiSwaggerHelpers::PayloadDefinition.new(payload).generate
23
23
  end
24
24
  end
25
+
26
+ def resources
27
+ @resources ||= []
28
+ end
29
+
30
+ # In production, the controller is loaded before the routes
31
+ # So, delay looking up the routes until they are loaded
32
+ def load!
33
+ resources.each { |r| load_resource(r) }
34
+ @loaded = true
35
+ end
36
+
37
+ def loaded?
38
+ !!@loaded
39
+ end
25
40
  end
26
41
 
27
42
  # Give Swagger::Blocks what it wants
28
43
  def index
44
+ self.class.load! unless self.class.loaded?
29
45
  render json: Swagger::Blocks.build_root_json([self.class])
30
46
  end
31
47
  end
@@ -6,6 +6,22 @@ module JsonapiSwaggerHelpers
6
6
  descriptions: {},
7
7
  only: [],
8
8
  except: [])
9
+ self.resources << {
10
+ base_path: base_path,
11
+ tags: tags,
12
+ descriptions: descriptions,
13
+ only: only,
14
+ except: except
15
+ }
16
+ end
17
+
18
+ def load_resource(config)
19
+ base_path = config[:base_path]
20
+ tags = config[:tags]
21
+ descriptions = config[:descriptions]
22
+ only = config[:only]
23
+ except = config[:only]
24
+
9
25
  actions = [:index, :show, :create, :update, :destroy]
10
26
  actions.select! { |a| only.include?(a) } unless only.empty?
11
27
  actions.reject! { |a| except.include?(a) } unless except.empty?
@@ -2,8 +2,25 @@ module JsonapiSwaggerHelpers
2
2
  class Util
3
3
  def self.controller_for(path)
4
4
  path = path.sub('{id}', '1')
5
- route = Rails.application.routes.recognize_path(path)
6
- "#{route[:controller]}_controller".classify.constantize
5
+ route = find_route(path)
6
+
7
+ if route
8
+ "#{route[:controller]}_controller".classify.constantize
9
+ else
10
+ Rails.logger.error("JsonapiSwaggerHelpers: No controller found for #{path}!") unless route
11
+ end
12
+ end
13
+
14
+ def self.find_route(path)
15
+ route = rails_route(path, 'GET')
16
+ route ||= rails_route(path, 'POST')
17
+ route ||= rails_route(path, 'PUT')
18
+ route ||= rails_route(path, 'DELETE')
19
+ route
20
+ end
21
+
22
+ def self.rails_route(path, method)
23
+ Rails.application.routes.recognize_path(path) rescue nil
7
24
  end
8
25
 
9
26
  def self.sideload_label(include_directive)
@@ -1,3 +1,3 @@
1
1
  module JsonapiSwaggerHelpers
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_swagger_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond