From b158f1e164355eab6c3f278cb670971485384906 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sat, 4 Apr 2020 23:05:26 +0100 Subject: [PATCH] add specific test for formData --- .../lib/rswag/specs/swagger_formatter.rb | 2 +- .../rswag/specs/swagger_formatter_spec.rb | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/rswag-specs/lib/rswag/specs/swagger_formatter.rb b/rswag-specs/lib/rswag/specs/swagger_formatter.rb index e00a970..7cda583 100644 --- a/rswag-specs/lib/rswag/specs/swagger_formatter.rb +++ b/rswag-specs/lib/rswag/specs/swagger_formatter.rb @@ -55,7 +55,7 @@ module Rswag v.each_pair do |_verb, value| is_hash = value.is_a?(Hash) if is_hash && value.dig(:parameters) - schema_param = value.dig(:parameters)&.find { |p| p[:in] == :body && p[:schema] } + schema_param = value.dig(:parameters)&.find { |p| (p[:in] == :body || p[:in] == :formData) && p[:schema] } mime_list = value.dig(:consumes) if value && schema_param && mime_list value[:requestBody] = { content: {} } unless value.dig(:requestBody, :content) diff --git a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb index 10a0631..1a9fdf0 100644 --- a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb +++ b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb @@ -240,6 +240,40 @@ module Rswag end end + context 'with oauth3 formData' do + let(:doc_2) do + { + paths: { + '/path/' => { + post: { + summary: 'Retrieve Nested Paths', + tags: ['nested Paths'], + produces: ['application/json'], + consumes: ['multipart/form-data'], + parameters: [{ + in: :formData, + schema: { type: :file } + },{ + in: :headers + }] + } + } + } + } + end + + it 'removes remaining consumes/produces' do + expect(doc_2[:paths]['/path/'][:post].keys).to eql([:summary, :tags, :parameters, :requestBody]) + end + + it 'duplicates params in: :formData to requestBody from consumes list' do + expect(doc_2[:paths]['/path/'][:post][:parameters]).to eql([{ in: :headers }]) + expect(doc_2[:paths]['/path/'][:post][:requestBody]).to eql(content: { + 'multipart/form-data' => { schema: { type: :file } } + }) + end + end + after do FileUtils.rm_r(swagger_root) if File.exist?(swagger_root) end