Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Prevent path/param drop when both fields have the same name. #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions coreapi/transports/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ def _get_params(method, encoding, fields, params=None):
if params is None:
return empty_params

# Collect path related variables
path = {
field.name: utils.validate_path_param(params[field.name])
for field in fields if field.location == 'path'
}
fields = [field for field in fields if field.location != 'path']
field_map = {field.name: field for field in fields}

path = {}
query = {}
data = {}
files = {}
Expand All @@ -113,6 +118,10 @@ def _get_params(method, encoding, fields, params=None):
seen_body = False

for key, value in params.items():
# Skip the value if we have it in the path only
if key in path.keys() and key not in field_map:
continue

if key not in field_map or not field_map[key].location:
# Default is 'query' for 'GET' and 'DELETE', and 'form' for others.
location = 'query' if method in ('GET', 'DELETE') else 'form'
Expand All @@ -124,9 +133,7 @@ def _get_params(method, encoding, fields, params=None):
location = 'body'

try:
if location == 'path':
path[key] = utils.validate_path_param(value)
elif location == 'query':
if location == 'query':
query[key] = utils.validate_query_param(value)
elif location == 'body':
data = utils.validate_body_param(value, encoding=encoding)
Expand Down