swaggard 4.1.0 → 4.2.0
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 +4 -4
- data/lib/swaggard/api_definition.rb +3 -1
- data/lib/swaggard/swagger/operation.rb +5 -0
- data/lib/swaggard/version.rb +1 -1
- data/lib/swaggard.rb +1 -0
- data/spec/fixtures/api.json +2 -1
- data/spec/fixtures/dummy/app/controllers/pets_controller.rb +1 -0
- data/spec/swaggard/api_definition_spec.rb +48 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22712f08a524289197fef03b0fa4b6e2f9b76bb998c78909ca0b8459a240b0fd
|
|
4
|
+
data.tar.gz: c6002db5029e1013e0597a041dae4ce1ce03622e5245647bd9249d2524e5ccaf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4cc784c4e3f5e930e5be443bc3c026da984194087c939867eea961e77b5259b4ec84daef72802bfbb44519cf2da5fb2834bdacc7eaafdc62e94cf4a213b2ee3
|
|
7
|
+
data.tar.gz: 06e9c4079d1dd6ae1f12a6bdd69b79279ae1d2481629e15a11b6beab3900fe1957f8b32b083951512a2dcc819eadbe6fe979b963ba177ba0b0f6bfc0bfab96e5
|
|
@@ -66,7 +66,9 @@ module Swaggard
|
|
|
66
66
|
def format_path(path)
|
|
67
67
|
return path unless Swaggard.configuration.exclude_base_path_from_paths
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
base_path = Swaggard.configuration.api_base_path
|
|
70
|
+
|
|
71
|
+
path.sub(/\A#{Regexp.escape(base_path)}/, '')
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
def build_components
|
|
@@ -19,6 +19,7 @@ module Swaggard
|
|
|
19
19
|
@summary = (yard_object.docstring.lines.first || '').chomp
|
|
20
20
|
@parameters = []
|
|
21
21
|
@responses = []
|
|
22
|
+
@deprecated = false
|
|
22
23
|
|
|
23
24
|
@description = (yard_object.docstring.lines[1..-1] || []).map(&:chomp).reject(&:empty?).compact.join("\n")
|
|
24
25
|
@http_method = verb
|
|
@@ -32,6 +33,8 @@ module Swaggard
|
|
|
32
33
|
case yard_tag.tag_name
|
|
33
34
|
when 'operation_id'
|
|
34
35
|
@operation_id = "#{@tag.name}.#{value}"
|
|
36
|
+
when 'deprecated'
|
|
37
|
+
@deprecated = true
|
|
35
38
|
when 'query_parameter'
|
|
36
39
|
@parameters << Parameters::Query.new(value)
|
|
37
40
|
when 'form_parameter'
|
|
@@ -98,6 +101,8 @@ module Swaggard
|
|
|
98
101
|
doc['requestBody'] = build_form_request_body(form_params)
|
|
99
102
|
end
|
|
100
103
|
|
|
104
|
+
doc['deprecated'] = true if @deprecated
|
|
105
|
+
|
|
101
106
|
doc
|
|
102
107
|
end
|
|
103
108
|
|
data/lib/swaggard/version.rb
CHANGED
data/lib/swaggard.rb
CHANGED
|
@@ -24,6 +24,7 @@ module Swaggard
|
|
|
24
24
|
def register_custom_yard_tags!
|
|
25
25
|
::YARD::Tags::Library.define_tag('Controller\'s tag', :tag)
|
|
26
26
|
::YARD::Tags::Library.define_tag('Operation id', :operation_id)
|
|
27
|
+
::YARD::Tags::Library.define_tag('Deprecated', :deprecated)
|
|
27
28
|
::YARD::Tags::Library.define_tag('Query parameter', :query_parameter)
|
|
28
29
|
::YARD::Tags::Library.define_tag('Form parameter', :form_parameter)
|
|
29
30
|
::YARD::Tags::Library.define_tag('Body required', :body_required)
|
data/spec/fixtures/api.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Swaggard::ApiDefinition do
|
|
4
|
+
describe '#format_path' do
|
|
5
|
+
subject(:formatted) { described_class.new.send(:format_path, path) }
|
|
6
|
+
|
|
7
|
+
let(:original_base_path) { Swaggard.configuration.api_base_path }
|
|
8
|
+
let(:original_exclude) { Swaggard.configuration.exclude_base_path_from_paths }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
original_base_path
|
|
12
|
+
original_exclude
|
|
13
|
+
Swaggard.configuration.api_base_path = '/api'
|
|
14
|
+
Swaggard.configuration.exclude_base_path_from_paths = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
after do
|
|
18
|
+
Swaggard.configuration.api_base_path = original_base_path
|
|
19
|
+
Swaggard.configuration.exclude_base_path_from_paths = original_exclude
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when the base path also appears inside a later path segment' do
|
|
23
|
+
let(:path) { '/api/partner/api_keys' }
|
|
24
|
+
|
|
25
|
+
it 'strips only the leading base path, not every occurrence' do
|
|
26
|
+
expect(formatted).to eq('/partner/api_keys')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'with a path that only contains the leading base path' do
|
|
31
|
+
let(:path) { '/api/partner/products' }
|
|
32
|
+
|
|
33
|
+
it 'strips the leading base path' do
|
|
34
|
+
expect(formatted).to eq('/partner/products')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context 'when exclude_base_path_from_paths is disabled' do
|
|
39
|
+
let(:path) { '/api/partner/api_keys' }
|
|
40
|
+
|
|
41
|
+
before { Swaggard.configuration.exclude_base_path_from_paths = false }
|
|
42
|
+
|
|
43
|
+
it 'returns the path unchanged' do
|
|
44
|
+
expect(formatted).to eq('/api/partner/api_keys')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swaggard
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adrian Gomez
|
|
@@ -162,6 +162,7 @@ files:
|
|
|
162
162
|
- spec/integration/openapi_spec.rb
|
|
163
163
|
- spec/integration/swaggard_spec.rb
|
|
164
164
|
- spec/spec_helper.rb
|
|
165
|
+
- spec/swaggard/api_definition_spec.rb
|
|
165
166
|
- spec/swaggard/parsers/property_spec.rb
|
|
166
167
|
- spec/swaggard/swagger/definition_spec.rb
|
|
167
168
|
- spec/swaggard/swagger/parameters/body_spec.rb
|
|
@@ -203,6 +204,7 @@ test_files:
|
|
|
203
204
|
- spec/integration/openapi_spec.rb
|
|
204
205
|
- spec/integration/swaggard_spec.rb
|
|
205
206
|
- spec/spec_helper.rb
|
|
207
|
+
- spec/swaggard/api_definition_spec.rb
|
|
206
208
|
- spec/swaggard/parsers/property_spec.rb
|
|
207
209
|
- spec/swaggard/swagger/definition_spec.rb
|
|
208
210
|
- spec/swaggard/swagger/parameters/body_spec.rb
|