jsonapi_swagger_helpers 0.4.1 → 0.4.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ae4cfb11abca237e55783d3638b67e6a163a9bc
|
|
4
|
+
data.tar.gz: 5b3c47fe4d0709438891357a1dfb2fe3c41955fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 =
|
|
6
|
-
|
|
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)
|