Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (open api writer): Allow to use same parameter name in different scopes #487

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions features/open_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation/writers/open_api_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? })
Expand Down