swaggard 4.3.0 → 4.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e58966e12de0580a4352f142f3dc5f76c75bef3366a81861acb1f7d5e1e7cf5b
4
- data.tar.gz: af8536b1d6047dd86f57500cba80b15c14a3ef127c394cf188d61c627ecb8af8
3
+ metadata.gz: 82824c4b34e6f3c0d12bec57f91ceda9710b50330c4a9f2d416fb8260d923a5d
4
+ data.tar.gz: bd5dbb90673afa20bed3825eb21c0b27be4277d59ba681c92ce06539928fa5ec
5
5
  SHA512:
6
- metadata.gz: 03db5dfd301998070525bb9eaf49910c99c2f7304ccbbbdbfa565a1556623a789131e6973c907f33e21a20f6d08bcc64205bb50fb0b80baea29ba27fd8af8afe
7
- data.tar.gz: 9c2d9d53a91b12f792fa0240ac31fdb90f1b7560d08d5416d2ed52931dcb546168236375b02b7a413599f8ac186f42991cff0ca78fee7446d8f2ebf3d822572b
6
+ metadata.gz: e4f9fddaf021be6c28ef710c815464c6a0b45e6c810320b6cdcc3f12c97cfd615014650d43732b62a604a49186af914a95c41736c8a8c6589e3ae1e3ae27cfb2
7
+ data.tar.gz: f73195b5684577d0b008b35d14fe81dbbc9f6f25e4e8474e0dd0367d3cd78e5cb35d12f614faf2b9a056f2b3de8e90696c6a0e39558123086437bdc8951ab27c
@@ -5,13 +5,14 @@ module Swaggard
5
5
  class Property
6
6
  attr_reader :id, :type, :description
7
7
 
8
- def initialize(name, type, description = '', required = false, options = [], deprecated = false)
8
+ def initialize(name, type, description = '', required = false, options = [], deprecated = false, nullable: false)
9
9
  @id = name
10
10
  @type = type
11
11
  @description = description
12
12
  @required = required
13
13
  @options = options
14
14
  @deprecated = deprecated
15
+ @nullable = nullable
15
16
  end
16
17
 
17
18
  def required?
@@ -27,6 +28,7 @@ module Swaggard
27
28
  result['description'] = @description if @description.present?
28
29
  result['enum'] = @options if @options.present?
29
30
  result['deprecated'] = true if @deprecated
31
+ result['nullable'] = true if @nullable
30
32
  result
31
33
  end
32
34
  end
@@ -1,3 +1,3 @@
1
1
  module Swaggard
2
- VERSION = '4.3.0'
2
+ VERSION = '4.4.0'
3
3
  end
@@ -29,5 +29,34 @@ describe Swaggard::Swagger::Property do
29
29
  expect(property.to_doc).not_to have_key('deprecated')
30
30
  expect(property).not_to be_deprecated
31
31
  end
32
+
33
+ it 'emits nullable when requested' do
34
+ property = described_class.new('name', type, nullable: true)
35
+
36
+ expect(property.to_doc).to eq('type' => 'string', 'nullable' => true)
37
+ end
38
+
39
+ it 'does not emit nullable when false or omitted' do
40
+ expect(described_class.new('name', type).to_doc).not_to have_key('nullable')
41
+ expect(described_class.new('name', type, nullable: false).to_doc).not_to have_key('nullable')
42
+ end
43
+
44
+ it 'preserves reference schemas when nullable' do
45
+ reference = Swaggard::Swagger::Type.new('Pet')
46
+ property = described_class.new('pet', reference, nullable: true)
47
+
48
+ expect(property.to_doc).to eq('$ref' => '#/components/schemas/Pet', 'nullable' => true)
49
+ end
50
+
51
+ it 'combines nullable with the existing positional metadata' do
52
+ property = described_class.new('status', type, 'Pet status', true, %w[active inactive], true, nullable: true)
53
+
54
+ expect(property.to_doc).to eq(
55
+ 'type' => 'string', 'description' => 'Pet status', 'enum' => %w[active inactive],
56
+ 'deprecated' => true, 'nullable' => true
57
+ )
58
+ expect(property).to be_required
59
+ expect(property).to be_deprecated
60
+ end
32
61
  end
33
62
  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.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gomez