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 +4 -4
- data/lib/swaggard/swagger/property.rb +3 -1
- data/lib/swaggard/version.rb +1 -1
- data/spec/swaggard/swagger/property_spec.rb +29 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 82824c4b34e6f3c0d12bec57f91ceda9710b50330c4a9f2d416fb8260d923a5d
|
|
4
|
+
data.tar.gz: bd5dbb90673afa20bed3825eb21c0b27be4277d59ba681c92ce06539928fa5ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/swaggard/version.rb
CHANGED
|
@@ -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
|