lib/dry/swagger/struct_parser.rb in dry-swagger-0.4.2 vs lib/dry/swagger/struct_parser.rb in dry-swagger-0.5.0
- old
+ new
@@ -13,11 +13,11 @@
attr_reader :keys
def initialize
@keys = {}
- @config = Config::StructConfiguration
+ @config = Dry::Swagger::Config::StructConfiguration
end
def to_h
{ keys: keys }
end
@@ -52,16 +52,22 @@
target_info = target.to_h if opts[:member]
type = opts[:array]? 'array' : 'hash'
- keys[key] = {
+ definition = {
type: type,
required: required,
@config.nullable_type => nullable,
**target_info
}
+
+ if opts[:oneOf]
+ keys[key] = keys[key] ? keys[key] << definition : [definition]
+ else
+ keys[key] = definition
+ end
end
def visit_key(node, opts = {})
name, required, rest = node
opts[:key] = name
@@ -111,11 +117,13 @@
def visit_sum(node, opts = {})
if node[0][0].equal?(:constrained)
opts[:nullable] = true
visit(node[1], opts) # ignore NilClass constrained
- elsif node[0][0].equal?(:struct)
- visit(node[0], opts) # grab left operand, this means if you have it defined as DTO1 | DTO2, it will grab DTO1
+ elsif node[0][0].equal?(:struct) && node[1][0].equal?(:struct)
+ opts[:oneOf] = true
+ visit(node[0], opts)
+ visit(node[1], opts)
end
end
def visit_struct(node, opts = {})
opts[:member] = true
\ No newline at end of file