dry-swagger 0.4.2 → 0.5.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/Gemfile.lock +1 -1
- data/lib/dry/swagger/documentation_generator.rb +43 -26
- data/lib/dry/swagger/struct_parser.rb +12 -4
- data/lib/dry/swagger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5179183ed4122bcf5042f8aa812b6830b1126ae00d4eb2975bd17203af2bf375
|
4
|
+
data.tar.gz: 9eb614eaaaca4752a39f9a77ef2fac3dffb4df2179a0c7e7f427d13f9f02333e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58dea258473d5fea4c521d699a2332ec8a444d15504b81ff3eefba0ef50c08371fe5d9b3fd7e2d3331613375f625bdb3ea54073dde31cfc20eafdc0d29e49202
|
7
|
+
data.tar.gz: 2ec6862a8021cb836101cac89b394482507a6b48021cfbf304b63c8753fe0bcefb822730a194ae869da6c83dc34e965af771a58b6052dc729cea0d528a97b6a4
|
data/Gemfile.lock
CHANGED
@@ -19,7 +19,11 @@ module Dry
|
|
19
19
|
documentation = { properties: {}, required: [] }
|
20
20
|
fields.each do |field_name, attributes_hash|
|
21
21
|
documentation[:properties][field_name] = generate_field_properties(attributes_hash)
|
22
|
-
|
22
|
+
if attributes_hash.is_a?(Hash)
|
23
|
+
documentation[:required] << field_name if attributes_hash.fetch(:required, true) && @config.enable_required_validation
|
24
|
+
else
|
25
|
+
documentation[:required] << field_name if attributes_hash[0].fetch(:required, true) && @config.enable_required_validation
|
26
|
+
end
|
23
27
|
|
24
28
|
rescue Errors::MissingTypeError => e
|
25
29
|
raise StandardError.new e.message % { field_name: field_name, valid_types: SWAGGER_FIELD_TYPE_DEFINITIONS.keys, attributes_hash: attributes_hash }
|
@@ -31,35 +35,48 @@ module Dry
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def generate_field_properties(attributes_hash)
|
34
|
-
if attributes_hash
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
items.merge(@config.nullable_type => true)
|
39
|
-
documentation = { type: :array, items: items }
|
40
|
-
elsif attributes_hash[:array] && attributes_hash.fetch(:type) != 'array'
|
41
|
-
items = SWAGGER_FIELD_TYPE_DEFINITIONS.fetch(attributes_hash.fetch(:type))
|
42
|
-
items = @config.enable_nullable_validation ?
|
43
|
-
items.merge(@config.nullable_type => attributes_hash.fetch(@config.nullable_type, false)) :
|
44
|
-
items.merge(@config.nullable_type => true)
|
45
|
-
documentation = { type: :array, items: items }
|
46
|
-
elsif attributes_hash[:type] == 'hash'
|
47
|
-
raise Errors::MissingHashSchemaError.new unless attributes_hash[:keys]
|
48
|
-
documentation = generate_documentation(attributes_hash.fetch(:keys))
|
49
|
-
else
|
50
|
-
documentation = SWAGGER_FIELD_TYPE_DEFINITIONS.fetch(attributes_hash.fetch(:type))
|
51
|
-
if attributes_hash[:enum] && @config.enable_enums
|
52
|
-
documentation = documentation.merge(enum: attributes_hash.fetch(:enum))
|
38
|
+
if attributes_hash.is_a?(Array)
|
39
|
+
properties = {}
|
40
|
+
attributes_hash.each_with_index do |_, index|
|
41
|
+
properties["definition_#{index + 1}"] = generate_field_properties(attributes_hash[index])
|
53
42
|
end
|
43
|
+
{
|
44
|
+
oneOf: attributes_hash.map{ |it| generate_field_properties(it) },
|
45
|
+
type: :object,
|
46
|
+
properties: properties,
|
47
|
+
example: 'Dynamic Field. See Model Definitions'
|
48
|
+
}
|
49
|
+
else
|
50
|
+
if attributes_hash[:type] == 'array'
|
51
|
+
items = generate_documentation(attributes_hash.fetch(:keys))
|
52
|
+
items = @config.enable_nullable_validation ?
|
53
|
+
items.merge(@config.nullable_type => attributes_hash.fetch(@config.nullable_type, false)) :
|
54
|
+
items.merge(@config.nullable_type => true)
|
55
|
+
documentation = { type: :array, items: items }
|
56
|
+
elsif attributes_hash[:array] && attributes_hash.fetch(:type) != 'array'
|
57
|
+
items = SWAGGER_FIELD_TYPE_DEFINITIONS.fetch(attributes_hash.fetch(:type))
|
58
|
+
items = @config.enable_nullable_validation ?
|
59
|
+
items.merge(@config.nullable_type => attributes_hash.fetch(@config.nullable_type, false)) :
|
60
|
+
items.merge(@config.nullable_type => true)
|
61
|
+
documentation = { type: :array, items: items }
|
62
|
+
elsif attributes_hash[:type] == 'hash'
|
63
|
+
raise Errors::MissingHashSchemaError.new unless attributes_hash[:keys]
|
64
|
+
documentation = generate_documentation(attributes_hash.fetch(:keys))
|
65
|
+
else
|
66
|
+
documentation = SWAGGER_FIELD_TYPE_DEFINITIONS.fetch(attributes_hash.fetch(:type))
|
67
|
+
if attributes_hash[:enum] && @config.enable_enums
|
68
|
+
documentation = documentation.merge(enum: attributes_hash.fetch(:enum))
|
69
|
+
end
|
54
70
|
|
55
|
-
|
56
|
-
|
71
|
+
if attributes_hash[:description] && @config.enable_descriptions
|
72
|
+
documentation = documentation.merge(description: attributes_hash.fetch(:description))
|
73
|
+
end
|
57
74
|
end
|
58
|
-
end
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
@config.enable_nullable_validation ?
|
77
|
+
documentation.merge(@config.nullable_type => attributes_hash.fetch(@config.nullable_type, false)) :
|
78
|
+
documentation.merge(@config.nullable_type => true)
|
79
|
+
end
|
63
80
|
|
64
81
|
rescue KeyError
|
65
82
|
raise Errors::MissingTypeError.new
|
@@ -15,7 +15,7 @@ module Dry
|
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@keys = {}
|
18
|
-
@config = Config::StructConfiguration
|
18
|
+
@config = Dry::Swagger::Config::StructConfiguration
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_h
|
@@ -54,12 +54,18 @@ module Dry
|
|
54
54
|
|
55
55
|
type = opts[:array]? 'array' : 'hash'
|
56
56
|
|
57
|
-
|
57
|
+
definition = {
|
58
58
|
type: type,
|
59
59
|
required: required,
|
60
60
|
@config.nullable_type => nullable,
|
61
61
|
**target_info
|
62
62
|
}
|
63
|
+
|
64
|
+
if opts[:oneOf]
|
65
|
+
keys[key] = keys[key] ? keys[key] << definition : [definition]
|
66
|
+
else
|
67
|
+
keys[key] = definition
|
68
|
+
end
|
63
69
|
end
|
64
70
|
|
65
71
|
def visit_key(node, opts = {})
|
@@ -113,8 +119,10 @@ module Dry
|
|
113
119
|
if node[0][0].equal?(:constrained)
|
114
120
|
opts[:nullable] = true
|
115
121
|
visit(node[1], opts) # ignore NilClass constrained
|
116
|
-
elsif node[0][0].equal?(:struct)
|
117
|
-
|
122
|
+
elsif node[0][0].equal?(:struct) && node[1][0].equal?(:struct)
|
123
|
+
opts[:oneOf] = true
|
124
|
+
visit(node[0], opts)
|
125
|
+
visit(node[1], opts)
|
118
126
|
end
|
119
127
|
end
|
120
128
|
|
data/lib/dry/swagger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jane-Terziev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A parser which converts dry-validation or dry-struct into valid swagger
|
14
14
|
documentation
|