From 39784e6e59624066827a78ec4fdc61e6967caeac Mon Sep 17 00:00:00 2001 From: Stanislav Kravchenko Date: Thu, 26 Nov 2020 22:53:20 +0300 Subject: [PATCH 1/2] Add example to test --- features/open_api.feature | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/features/open_api.feature b/features/open_api.feature index a24b7094..fb9c43f9 100644 --- a/features/open_api.feature +++ b/features/open_api.feature @@ -193,6 +193,8 @@ Feature: Generate Open API Specification from test examples parameter :name, 'The order name', required: true, scope: :data, with_example: true parameter :amount, required: false, scope: :data, with_example: true parameter :description, 'The order description', required: true, scope: :data, with_example: true + parameter :address, 'The seller address', scope: [:data, :seller] + parameter :address, 'The buyer address', scope: [:data, :buyer] header "Content-Type", "application/json" @@ -697,6 +699,24 @@ Feature: Generate Open API Specification from test examples "type": "string", "example": "fast order", "description": "The order description" + }, + "seller": { + "type": "object", + "properties": { + "address": { + "type": "string", + "description": "The seller address" + } + } + }, + "buyer": { + "type": "object", + "properties": { + "address": { + "type": "string", + "description": "The buyer address" + } + } } }, "required": [ From f3b1089bdf14269218b0b59af94ffe6244758e56 Mon Sep 17 00:00:00 2001 From: Stanislav Kravchenko Date: Fri, 27 Nov 2020 09:08:10 +0300 Subject: [PATCH 2/2] Fix uniq filter for parameters in open api writer --- lib/rspec_api_documentation/writers/open_api_writer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec_api_documentation/writers/open_api_writer.rb b/lib/rspec_api_documentation/writers/open_api_writer.rb index ed5d0420..f7df87c1 100644 --- a/lib/rspec_api_documentation/writers/open_api_writer.rb +++ b/lib/rspec_api_documentation/writers/open_api_writer.rb @@ -159,7 +159,7 @@ def extract_schema(fields) end def extract_parameters(example) - parameters = example.extended_parameters.uniq { |parameter| parameter[:name] } + parameters = example.extended_parameters.uniq { |parameter| [parameter[:name], parameter[:scope]] } extract_known_parameters(parameters.select { |p| !p[:in].nil? }) + extract_unknown_parameters(example, parameters.select { |p| p[:in].nil? })