swaggard 1.4.0 → 1.5.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
2
  SHA256:
3
- metadata.gz: ed70536923570dc261e856336612392dbf360df9e5fbe0854c435eca43be1379
4
- data.tar.gz: a838d6c384fe16bc135463d5c356871bc949fa5410f079822b7e79f757817733
3
+ metadata.gz: d74cf8955c1980e4153b8a1af250e09471b2bdce60e7e59aba84520aaeb66c40
4
+ data.tar.gz: c82d51b65fe90228bb4428c16426332a69a2af202e442a4e3b728cf6d48581c7
5
5
  SHA512:
6
- metadata.gz: 99b13f5741da156d8d9f442131f4fd7b5d2cb9c69d5218ae64bcb14beb0937a4918bf7ea3da6cd7ea102c4e99a5b3ccf564107046745af55b45f46fa9442b7e4
7
- data.tar.gz: 99c290f273f52991dd9f7fbd26bd3d40e170991e5e5eadbc6417e8d3e228a2d27f3fc5d953263539bb7f35e6096b1241e7b8d759bb6a46ce02f32f65d4ca89ab
6
+ metadata.gz: ca72d1996855482ef03474325479dae941fbd68b5d2ab7d928c0c132992156bcfe91391ab5bb3aa9b6c48174171a66d9cbf67006e77fab977aec2daab5b1bb9d
7
+ data.tar.gz: 5d824f78de1e1a2096899be9378e336631fdb4abd5a6b3185d9d6e368353e73a142cf8e942b5315c2557b2f8ef45e48fa5e092cd3f54f0eacf9ff0a5e2847d25
data/README.md CHANGED
@@ -49,7 +49,7 @@ Make sure the asset pipeline is enabled by either requiring all railties
49
49
  or just the sprockets one:
50
50
 
51
51
  # config/application.rb
52
-
52
+
53
53
  require 'sprockets/railtie'
54
54
 
55
55
  Access your service documentation
@@ -154,7 +154,7 @@ Will generate
154
154
 
155
155
  ### Controllers
156
156
 
157
- - `@tag name` This is used to indicate under what `name` tag this controller needs to be grouped. If not provided it will use the full controller class name.
157
+ - `@tag name` This is used to indicate under what `name` tag this controller needs to be grouped. If not provided and Con.ignore_untagged_controllers = true it will use the full controller class name.
158
158
  - `@query_parameter [type] name` This is used to indicate that your action receives the `name` parameter of `type` on the query string.
159
159
  - `@body_parameter [type] name` This is used to indicate that your action receives the `name` parameter of `type` on the body.
160
160
  - `@response_class type` This is used to indicate that your action returns a response of `type`.
@@ -163,6 +163,15 @@ Will generate
163
163
  - `@form_parameter`
164
164
  - `@parameter_list`
165
165
 
166
+ If you want to generate documentation for all controllers even for those that don't have a tag do:
167
+ # config/initializers/swaggard.rb
168
+ Swaggard.configure do |config|
169
+ ...
170
+ config.ignore_untagged_controllers = false
171
+ ...
172
+ end
173
+
174
+
166
175
  ### Models
167
176
 
168
177
  - `@attr [type] name` This is used to indicate that your models has an attribute `name` of `type`.
@@ -52,7 +52,7 @@ module Swaggard
52
52
  'tags' => @tags.map { |_, tag| tag.to_doc },
53
53
  'paths' => Hash[@paths.values.map { |path| [format_path(path.path), path.to_doc] }],
54
54
  'definitions' => Hash[@definitions.merge(Swaggard.configuration.definitions).map { |id, definition| [id, definition.to_doc(@definitions)] }]
55
- }
55
+ }.merge(security_definitions)
56
56
  end
57
57
 
58
58
  private
@@ -62,5 +62,22 @@ module Swaggard
62
62
 
63
63
  path.gsub(Swaggard.configuration.api_base_path, '')
64
64
  end
65
+
66
+ def security_definitions
67
+ security_definitions = Swaggard.configuration.security_definitions
68
+
69
+ return {} if security_definitions.empty? && Swaggard.configuration.security.empty?
70
+
71
+ Swaggard.configuration.security.keys.each do |authentication_type|
72
+ next if security_definitions.key?(authentication_type)
73
+
74
+ warn "#{authentication_type} not supported by securityDefinitions"
75
+ end
76
+
77
+ {
78
+ 'securityDefinitions' => security_definitions,
79
+ 'security' => Swaggard.configuration.security,
80
+ }
81
+ end
65
82
  end
66
83
  end
@@ -21,7 +21,7 @@ module Swaggard
21
21
  :language, :additional_parameters, :schemes, :ignore_undocumented_paths,
22
22
  :license_name, :exclude_base_path_from_paths, :default_response_description,
23
23
  :default_response_status_code, :excluded_paths, :path_parameter_description,
24
- :ignore_put_if_patch_exists
24
+ :ignore_put_if_patch_exists, :ignore_untagged_controllers
25
25
 
26
26
  def swagger_version
27
27
  @swagger_version ||= '2.0'
@@ -117,6 +117,12 @@ module Swaggard
117
117
  @ignore_undocumented_paths = false
118
118
  end
119
119
 
120
+ def ignore_untagged_controllers
121
+ return @ignore_untagged_controllers unless @ignore_untagged_controllers.nil?
122
+
123
+ @ignore_untagged_controllers = true
124
+ end
125
+
120
126
  def exclude_base_path_from_paths
121
127
  return @exclude_base_path_from_paths unless @exclude_base_path_from_paths.nil?
122
128
 
@@ -164,5 +170,21 @@ module Swaggard
164
170
 
165
171
  @ignore_put_if_patch_exists = false
166
172
  end
173
+
174
+ def security_definitions
175
+ @security_definitions ||= {}
176
+ end
177
+
178
+ def security
179
+ @security ||= {}
180
+ end
181
+
182
+ def add_security_definition(authentication_key, definition)
183
+ security_definitions[authentication_key] = definition
184
+ end
185
+
186
+ def add_security(authentication_key, scopes = [])
187
+ security[authentication_key] = scopes
188
+ end
167
189
  end
168
190
  end
@@ -25,6 +25,10 @@ module Swaggard
25
25
  def get_tags(yard_object)
26
26
  tags = yard_object.tags.select { |tag| tag.tag_name == 'tag' }
27
27
 
28
+ if tags.empty? && !Swaggard.configuration.ignore_untagged_controllers
29
+ tags << nil
30
+ end
31
+
28
32
  tags.map { |tag| Swagger::Tag.new(yard_object, tag) }
29
33
  end
30
34
  end
@@ -94,6 +94,7 @@ module Swaggard
94
94
  def definitions
95
95
  @responses.map(&:definition).compact.inject({}) do |definitions, definition|
96
96
  definitions[definition.id] = definition
97
+ definitions
97
98
  end.tap do |definitions|
98
99
  next unless @body_parameter
99
100
 
@@ -1,3 +1,3 @@
1
1
  module Swaggard
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -6,9 +6,6 @@ require File.expand_path('../../../../../lib/swaggard', __FILE__)
6
6
  module Dummy
7
7
  class Application < Rails::Application
8
8
  config.root = File.expand_path('../../', __FILE__)
9
-
10
- # Disable the asset pipeline.
11
- config.assets.enabled = false
12
9
  end
13
10
  end
14
11
 
File without changes
@@ -12,6 +12,7 @@ describe Swaggard, '.get_doc' do
12
12
  Swaggard.configure do |config|
13
13
  config.controllers_path = controller_path
14
14
  config.routes = Dummy::Application.routes.routes
15
+ config.ignore_untagged_controllers = false
15
16
  end
16
17
 
17
18
  swagger_json = JSON.dump(Swaggard.get_doc(host))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swaggard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gomez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-14 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -194,6 +194,7 @@ files:
194
194
  - spec/fixtures/dummy/config/application.rb
195
195
  - spec/fixtures/dummy/config/environments/development.rb
196
196
  - spec/fixtures/dummy/config/routes.rb
197
+ - spec/fixtures/dummy/log/development.log
197
198
  - spec/fixtures/swagger_schema.json
198
199
  - spec/integration/swaggard_spec.rb
199
200
  - spec/spec_helper.rb
@@ -216,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  - !ruby/object:Gem::Version
217
218
  version: '0'
218
219
  requirements: []
219
- rubygems_version: 3.2.15
220
+ rubygems_version: 3.3.7
220
221
  signing_key:
221
222
  specification_version: 4
222
223
  summary: 'Swaggard: Swagger Rails REST API doc using yard YARD'
@@ -228,6 +229,7 @@ test_files:
228
229
  - spec/fixtures/dummy/config/application.rb
229
230
  - spec/fixtures/dummy/config/environments/development.rb
230
231
  - spec/fixtures/dummy/config/routes.rb
232
+ - spec/fixtures/dummy/log/development.log
231
233
  - spec/fixtures/swagger_schema.json
232
234
  - spec/integration/swaggard_spec.rb
233
235
  - spec/spec_helper.rb