ree_lib 1.3.8 → 1.3.9

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
  SHA256:
3
- metadata.gz: 91fc8dfb82375a041a8174ecb6845cc67b808ff127789f7a0cfc7acf77dd070d
4
- data.tar.gz: 9559a1c0ab2a12444b80321ffeee129104eb50e3ab18b1245190747eec34e168
3
+ metadata.gz: 237cf0a00005f59af6c0741f79302159d84433b60b63e401baa4ae95ab0dd2ae
4
+ data.tar.gz: f9c00515a41e9d78fc2c3ac1785d5a8a21d1f4142461537299e4c1678d4a6b61
5
5
  SHA512:
6
- metadata.gz: 043c917b9aedca9ead3eda2ebf43e1ad5404abf818b6a8aa63fc2827b677ad850785c4ebdb46b135e1f9967bb1cc66b04524b0124d6ea5218cabee98b348e90e
7
- data.tar.gz: ca3d90247859cb1dde09162aa2e3479f6e9cacc038ea8b083bda2fa9704015314cce9b39154d639b0c60f9caf1f0268dd3c89bfc383e999f556b66193225ed64
6
+ metadata.gz: c712530b729aa1e48d53de393ee737b7605c233108940e78f09f4561c36b69c413136880f8b72f73f694d4a6ac5ee7e4010d2d46ff2dcdb30450ad1fd2bb9a56
7
+ data.tar.gz: e148d3f589e0c2863a9b1958d903458407c1646f0fca6ca79c5fb0839893c0bc00059b4a80a9c0b45cf6710e4e9b6802f6a94ee9b8958fa485701164cd99a240
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../ree
3
3
  specs:
4
- ree (1.3.2)
4
+ ree (1.3.3)
5
5
  base64
6
6
  commander
7
7
  logger
@@ -9,7 +9,7 @@ PATH
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- ree_lib (1.3.8)
12
+ ree_lib (1.3.9)
13
13
  bigdecimal
14
14
  binding_of_caller
15
15
  i18n
@@ -17,7 +17,8 @@ class Roda
17
17
 
18
18
  module ClassMethods
19
19
  def ree_routes(routes, swagger_title: "", swagger_description: "",
20
- swagger_version: "", swagger_url: "", api_url: "")
20
+ swagger_version: "", swagger_url: "", api_url: "",
21
+ swagger_include_internal: nil)
21
22
  @ree_routes ||= []
22
23
  @ree_routes += routes
23
24
 
@@ -27,12 +28,17 @@ class Roda
27
28
  opts[:ree_routes_swagger_url] = swagger_url
28
29
  opts[:ree_routes_api_url] = api_url
29
30
 
31
+ # nil keeps the global default (Ree.hide_internal_swagger_endpoints);
32
+ # pass true/false to force one app to differ from it.
33
+ swagger_opts = swagger_include_internal.nil? ? {} : { include_internal: swagger_include_internal }
34
+
30
35
  opts[:ree_routes_swagger] = ReeRoda::BuildSwaggerFromRoutes.new.call(
31
36
  @ree_routes,
32
37
  opts[:ree_routes_swagger_title],
33
38
  opts[:ree_routes_swagger_description],
34
39
  opts[:ree_routes_swagger_version],
35
- opts[:ree_routes_api_url]
40
+ opts[:ree_routes_api_url],
41
+ **swagger_opts
36
42
  )
37
43
 
38
44
  build_routes_proc
@@ -7,8 +7,19 @@ class ReeRoda::BuildSwaggerFromRoutes
7
7
  link "ree_swagger/dto/endpoint_dto", -> { EndpointDto }
8
8
  end
9
9
 
10
- contract(ArrayOf[ReeRoutes::Route], String, String, String, String => Hash)
11
- def call(routes, title, description, version, api_url)
10
+ contract(
11
+ ArrayOf[ReeRoutes::Route], String, String, String, String,
12
+ Ksplat[include_internal?: Bool] => Hash
13
+ )
14
+ def call(routes, title, description, version, api_url, **opts)
15
+ # Defaults to the global switch (see Ree.hide_internal_swagger_endpoints),
16
+ # so one codebase can serve a public and an internal document.
17
+ include_internal = opts.fetch(:include_internal) {
18
+ !Ree.hide_internal_swagger_endpoints?
19
+ }
20
+
21
+ routes = routes.select(&:public?) if !include_internal
22
+
12
23
  endpoints = routes.map do |route|
13
24
  method_decorator = Ree::Contracts.get_method_decorator(
14
25
  route.action.klass, :call, scope: :instance
@@ -24,6 +24,8 @@ module ReeRoutes
24
24
  include Ree::Contracts::Core
25
25
  include Ree::Contracts::ArgContracts
26
26
 
27
+ ADMIN_PATH_SEGMENT = "admin"
28
+
27
29
  def routes(name, &proc)
28
30
  raise ArgumentError.new("block is required") if !block_given?
29
31
 
@@ -87,6 +89,14 @@ module ReeRoutes
87
89
  raise ArgumentError.new("action, summary and auth scope should be provided for #{builder.get_route.inspect}")
88
90
  end
89
91
 
92
+ if builder.get_route.visibility.nil? && admin_path?(path)
93
+ raise ArgumentError.new(
94
+ "admin route #{path} must declare visibility explicitly: " \
95
+ "`visibility :internal` to keep it out of generated swagger, " \
96
+ "or `visibility :public` if it is intentionally documented"
97
+ )
98
+ end
99
+
90
100
  route = builder.get_route
91
101
 
92
102
  @dsl.link(route.action.name, from: route.action.package_name)
@@ -98,6 +108,13 @@ module ReeRoutes
98
108
  @routes << route
99
109
  route
100
110
  end
111
+
112
+ # Forgetting `visibility` on an admin route is invisible in review and
113
+ # silently publishes it, so make it a boot-time failure instead.
114
+ contract String => Bool
115
+ def admin_path?(path)
116
+ path.split("/").include?(ADMIN_PATH_SEGMENT)
117
+ end
101
118
  end
102
119
  end
103
120
  end
@@ -2,7 +2,17 @@
2
2
 
3
3
  class ReeRoutes::Route
4
4
  attr_accessor :summary, :request_method, :serializer, :respond_to,
5
- :sections, :action, :route, :warden_scopes, :path, :override
5
+ :sections, :action, :route, :warden_scopes, :path, :override,
6
+ :visibility
7
+
8
+ # Routing always includes every route; visibility only affects generated docs.
9
+ def public?
10
+ visibility.nil? || visibility == :public
11
+ end
12
+
13
+ def internal?
14
+ !public?
15
+ end
6
16
 
7
17
  def valid?
8
18
  !action.nil? && !summary.nil? && !warden_scopes.nil? && !warden_scopes.empty?
@@ -5,6 +5,8 @@ require_relative "route"
5
5
  class ReeRoutes::RouteBuilder
6
6
  Redirect = Struct.new(:path, :code)
7
7
 
8
+ VISIBILITIES = [:public, :internal].freeze
9
+
8
10
  def initialize
9
11
  @route = ReeRoutes::Route.new
10
12
  @route.respond_to = :json
@@ -42,6 +44,17 @@ class ReeRoutes::RouteBuilder
42
44
  @route.summary = str
43
45
  end
44
46
 
47
+ contract Symbol => Symbol
48
+ def visibility(value)
49
+ if !VISIBILITIES.include?(value)
50
+ raise ArgumentError.new(
51
+ "visibility should be one of #{VISIBILITIES.inspect}, got #{value.inspect}"
52
+ )
53
+ end
54
+
55
+ @route.visibility = value
56
+ end
57
+
45
58
  contract Symbol, Symbol => nil
46
59
  def serializer(name, from:)
47
60
  object = Ree.container.packages_facade.get_object(from, name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.3.8"
4
+ VERSION = "1.3.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov