lib/rspec/rails/api/open_api_renderer.rb in rspec-rails-api-0.6.0 vs lib/rspec/rails/api/open_api_renderer.rb in rspec-rails-api-0.6.1

- old
+ new

@@ -41,11 +41,11 @@ # @param name [String] Human friendly name # @param definition [Hash] Security scheme definition as per https://swagger.io/specification/#security-scheme-object def add_security_scheme(reference, name, definition) raise "Security scheme #{reference} is already defined" if @api_security.key? reference - definition[:name] = name + definition[:name] = name unless reference == :basic @api_security[reference] = definition end ## # Merges example context definition with the renderer data @@ -239,10 +239,12 @@ property[:items] = { type: field.attributes } elsif field.type == :object && field.attributes.is_a?(Symbol) property = { '$ref' => "#/components/schemas/#{field.attributes}" } elsif field.type == :array && field.attributes.is_a?(Symbol) property = { type: :array, items: { '$ref' => "#/components/schemas/#{field.attributes}" } } + elsif field.type == :array + property = { type: :array, items: process_entity(field.attributes) } end required.push name unless field.required == false schema[:properties][name] = property @@ -418,19 +420,23 @@ } response end - def response_schema(expectations) # rubocop:disable Metrics/MethodLength + def response_schema(expectations) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity if expectations[:many] items = if PRIMITIVES.include?(expectations[:many]) { type: expectations[:many] } else { '$ref' => "#/components/schemas/#{expectations[:many]}" } end { type: 'array', items: items } elsif expectations[:one] - if PRIMITIVES.include?(expectations[:one]) + # Unspecified arrays + if expectations[:one] == :array + { type: :array, items: {} } + # Array of specified type + elsif PRIMITIVES.include?(expectations[:one]) { type: expectations[:one] } else { '$ref' => "#/components/schemas/#{expectations[:one]}" } end end