swagger_docs_generator 0.3.4 → 0.3.5.pre.31

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: 1d825270a25e0789b5851ef0bfa6e9c2cacdcac8
4
- data.tar.gz: 8d679b4c99e83c4af41e1f54ef2a14615100e183
3
+ metadata.gz: 7aa2fd2dd584ba032e296ee81ca9ca2ee90359d0
4
+ data.tar.gz: 86a57eabc9caeca89f60ce027ba0a4c73b0b0cde
5
5
  SHA512:
6
- metadata.gz: c573bf0b9f189113f3de3f2bff8be2e7c6a8fc849ffb7d7621016c9277aefdb1fe7206a3f7fc55c0d77b771d2e4b17e5c498968589b94a288a89b31fb9bad9a1
7
- data.tar.gz: 4b07e3ca4a2e0d51e797fcadd89aa1ab28175b601e384ff57285cfdb4d73cece8fad3de15762617ca0a6e2b4f59d392227c69dd2049667a7db76ea7ef7f27891
6
+ metadata.gz: e9d9365e85dad68166b5e0bae24ca9e82f157789f06efbbec9216221b63f5341b5a6c3b36e51c42e5008faa8d0ff36174053001346fa32d5b67b1ddf6e704b8f
7
+ data.tar.gz: d3fa4e5e457d1cd54f327bbee5eefed8087e06d02db6225235788e6cf820a85f50e64697828e533a175c03ea33685ad4a6361e4653f728ba94bfc2cf8ed4fd6d
@@ -18,7 +18,7 @@ module SwaggerDocsGenerator
18
18
  # @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
19
19
  class Configuration
20
20
  # Accessors with default value
21
- attr_accessor :swagger, :cleanning, :base_path
21
+ attr_accessor :swagger, :cleanning, :base_path, :compress
22
22
 
23
23
  # Accessors without default value
24
24
  attr_accessor :schemes, :consumes, :produces, :host, :external_docs,
@@ -29,6 +29,7 @@ module SwaggerDocsGenerator
29
29
  @swagger = '2.0'
30
30
  @base_path = '/'
31
31
  @cleanning = true
32
+ @compress = false
32
33
  end
33
34
  end
34
35
 
@@ -26,8 +26,11 @@ module SwaggerDocsGenerator
26
26
  def generate_swagger_file
27
27
  delete_file_before
28
28
  File.open(@swagger_file, 'a+') do |file|
29
- # file.puts write_in_swagger_file.to_json
30
- file.puts JSON.pretty_generate write_in_swagger_file
29
+ file.write(if SwaggerDocsGenerator.configure.compress
30
+ write_in_swagger_file.to_json
31
+ else
32
+ JSON.pretty_generate write_in_swagger_file
33
+ end)
31
34
  end
32
35
  end
33
36
 
@@ -5,7 +5,7 @@ module SwaggerDocsGenerator
5
5
  # Name to gem
6
6
  GEM = 'swagger_docs_generator'
7
7
  # Version to gem
8
- VERSION = '0.3.4'
8
+ VERSION = '0.3.5'
9
9
  # Authors contributed to gem
10
10
  AUTHORS = ['VAILLANT Jeremy'].freeze
11
11
  # Email to ahuthors
@@ -7,14 +7,15 @@ module SwaggerDocsGenerator
7
7
  module Actions
8
8
  # Write parameter type :header
9
9
  class Header < Parameter
10
+ FIELDS = %w[description format default enum].freeze
11
+
10
12
  def to_hash
11
13
  {
12
14
  in: :header,
13
- name: @name.nil? ? 'header' : @name,
14
- description: @description.nil? ? '' : @description,
15
+ name: @name,
15
16
  required: @required.nil? ? true : @required,
16
- type: @type.nil? ? '' : @type
17
- }
17
+ type: @type
18
+ }.merge(no_mandatory_field)
18
19
  end
19
20
 
20
21
  private
@@ -22,6 +23,27 @@ module SwaggerDocsGenerator
22
23
  def type(text)
23
24
  @type = text
24
25
  end
26
+
27
+ def default(text)
28
+ @default = text
29
+ end
30
+
31
+ def enum(array)
32
+ @enum = array
33
+ end
34
+
35
+ def format(text)
36
+ @format = text
37
+ end
38
+
39
+ def no_mandatory_field
40
+ hash = {}
41
+ FIELDS.each do |parameter|
42
+ value = instance_variable_get("@#{parameter}")
43
+ hash.merge!(parameter.to_sym => value) if value.present?
44
+ end
45
+ hash
46
+ end
25
47
  end
26
48
  end
27
49
  end
@@ -57,21 +57,6 @@ RSpec.shared_examples 'parameters header haves' do
57
57
  let(:result) { param_type }
58
58
  include_examples 'parameter equal', :@type
59
59
  end
60
-
61
- it do
62
- name = param_name.nil? ? 'header' : param_name
63
- description = param_description.nil? ? '' : param_description
64
- required = param_required.nil? ? true : param_required
65
- type = param_type.nil? ? '' : param_type
66
-
67
- expect(param.to_hash).to eql(
68
- in: :header,
69
- name: name,
70
- description: description,
71
- required: required,
72
- type: type
73
- )
74
- end
75
60
  end
76
61
 
77
62
  # Test for parameter PATH
@@ -8,55 +8,244 @@ describe SwaggerDocsGenerator::Actions::Header, type: :parser,
8
8
  let(:param_description) { nil }
9
9
  let(:param_required) { nil }
10
10
  let(:param_type) { nil }
11
- let(:param) do
12
- pname = param_name
13
- pdescription = param_description
14
- prequired = param_required
15
- ptype = param_type
16
- SwaggerDocsGenerator::Actions::Parameter.new do
17
- header do
18
- name pname
19
- description pdescription
20
- required prequired
21
- type ptype
22
- end
23
- end
24
- end
11
+ let(:param_default) { nil }
12
+ let(:param_enum) { nil }
13
+ let(:param_format) { nil }
25
14
 
26
15
  context 'when attribute complete' do
27
16
  let(:param_name) { Faker::Color.color_name }
28
17
  let(:param_description) { Faker::Beer.name }
29
18
  let(:param_required) { Faker::Boolean.boolean }
30
19
  let(:param_type) { Faker::Name.first_name }
20
+ let(:param_default) { Faker::Name.first_name }
21
+ let(:param_format) { Faker::Name.first_name }
22
+ let(:param_enum) { Faker::Lorem.words(4, true) }
23
+
24
+ let(:param) do
25
+ pname = param_name
26
+ pdescription = param_description
27
+ prequired = param_required
28
+ ptype = param_type
29
+ pdefault = param_default
30
+ pformat = param_format
31
+ penum = param_enum
32
+ SwaggerDocsGenerator::Actions::Parameter.new do
33
+ header do
34
+ name pname
35
+ description pdescription
36
+ required prequired
37
+ type ptype
38
+ default pdefault
39
+ format pformat
40
+ enum penum
41
+ end
42
+ end
43
+ end
31
44
 
45
+ it do
46
+ expect(param.to_hash).to eql(
47
+ in: :header,
48
+ name: param_name,
49
+ description: param_description,
50
+ required: param_required,
51
+ type: param_type,
52
+ default: param_default,
53
+ format: param_format,
54
+ enum: param_enum
55
+ )
56
+ end
32
57
  it_behaves_like 'parameters header haves'
33
58
  end
34
59
 
35
60
  context 'when attribute is incomplete' do
61
+ let(:param) do
62
+ SwaggerDocsGenerator::Actions::Parameter.new do
63
+ header do
64
+ end
65
+ end
66
+ end
67
+
68
+ it do
69
+ expect(param.to_hash).to eql(
70
+ in: :header,
71
+ name: nil,
72
+ required: true,
73
+ type: nil
74
+ )
75
+ end
76
+
36
77
  it_behaves_like 'parameters header haves'
37
78
  end
38
79
 
39
80
  context 'when name attribute alone' do
40
81
  let(:param_name) { Faker::Color.color_name }
41
82
 
83
+ let(:param) do
84
+ pname = param_name
85
+ SwaggerDocsGenerator::Actions::Parameter.new do
86
+ header do
87
+ name pname
88
+ end
89
+ end
90
+ end
91
+
92
+ it do
93
+ expect(param.to_hash).to eql(
94
+ in: :header,
95
+ name: param_name,
96
+ required: true,
97
+ type: nil
98
+ )
99
+ end
100
+
42
101
  it_behaves_like 'parameters header haves'
43
102
  end
44
103
 
45
104
  context 'when description attribute alone' do
46
105
  let(:param_description) { Faker::Beer.name }
47
106
 
107
+ let(:param) do
108
+ pdescription = param_description
109
+ SwaggerDocsGenerator::Actions::Parameter.new do
110
+ header do
111
+ description pdescription
112
+ end
113
+ end
114
+ end
115
+
116
+ it do
117
+ expect(param.to_hash).to eql(
118
+ in: :header,
119
+ name: nil,
120
+ required: true,
121
+ type: nil,
122
+ description: param_description
123
+ )
124
+ end
125
+
48
126
  it_behaves_like 'parameters header haves'
49
127
  end
50
128
 
51
129
  context 'when required attribute alone' do
52
130
  let(:param_required) { Faker::Boolean.boolean }
53
131
 
132
+ let(:param) do
133
+ prequired = param_required
134
+ SwaggerDocsGenerator::Actions::Parameter.new do
135
+ header do
136
+ required prequired
137
+ end
138
+ end
139
+ end
140
+
141
+ it do
142
+ expect(param.to_hash).to eql(
143
+ in: :header,
144
+ name: nil,
145
+ required: param_required,
146
+ type: nil
147
+ )
148
+ end
149
+
54
150
  it_behaves_like 'parameters header haves'
55
151
  end
56
152
 
57
153
  context 'when type attribute alone' do
58
154
  let(:param_type) { Faker::Name.first_name }
59
155
 
156
+ let(:param) do
157
+ ptype = param_type
158
+ SwaggerDocsGenerator::Actions::Parameter.new do
159
+ header do
160
+ type ptype
161
+ end
162
+ end
163
+ end
164
+
165
+ it do
166
+ expect(param.to_hash).to eql(
167
+ in: :header,
168
+ name: nil,
169
+ required: true,
170
+ type: param_type
171
+ )
172
+ end
173
+
174
+ it_behaves_like 'parameters header haves'
175
+ end
176
+
177
+ context 'when default attribute alone' do
178
+ let(:param_default) { Faker::Name.first_name }
179
+
180
+ let(:param) do
181
+ pdefault = param_default
182
+ SwaggerDocsGenerator::Actions::Parameter.new do
183
+ header do
184
+ default pdefault
185
+ end
186
+ end
187
+ end
188
+
189
+ it do
190
+ expect(param.to_hash).to eql(
191
+ in: :header,
192
+ name: nil,
193
+ required: true,
194
+ type: nil,
195
+ default: param_default
196
+ )
197
+ end
198
+
199
+ it_behaves_like 'parameters header haves'
200
+ end
201
+
202
+ context 'when format attribute alone' do
203
+ let(:param_format) { Faker::Name.first_name }
204
+
205
+ let(:param) do
206
+ pformat = param_format
207
+ SwaggerDocsGenerator::Actions::Parameter.new do
208
+ header do
209
+ format pformat
210
+ end
211
+ end
212
+ end
213
+
214
+ it do
215
+ expect(param.to_hash).to eql(
216
+ in: :header,
217
+ name: nil,
218
+ required: true,
219
+ type: nil,
220
+ format: param_format
221
+ )
222
+ end
223
+
224
+ it_behaves_like 'parameters header haves'
225
+ end
226
+
227
+ context 'when default attribute alone' do
228
+ let(:param_enum) { Faker::Lorem.words(4, true) }
229
+
230
+ let(:param) do
231
+ penum = param_enum
232
+ SwaggerDocsGenerator::Actions::Parameter.new do
233
+ header do
234
+ enum penum
235
+ end
236
+ end
237
+ end
238
+
239
+ it do
240
+ expect(param.to_hash).to eql(
241
+ in: :header,
242
+ name: nil,
243
+ required: true,
244
+ type: nil,
245
+ enum: param_enum
246
+ )
247
+ end
248
+
60
249
  it_behaves_like 'parameters header haves'
61
250
  end
62
251
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_docs_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5.pre.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-10 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -325,9 +325,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
325
  version: '0'
326
326
  required_rubygems_version: !ruby/object:Gem::Requirement
327
327
  requirements:
328
- - - ">="
328
+ - - ">"
329
329
  - !ruby/object:Gem::Version
330
- version: '0'
330
+ version: 1.3.1
331
331
  requirements: []
332
332
  rubyforge_project:
333
333
  rubygems_version: 2.4.5