Skip to content

Commit 7147ec5

Browse files
committed
Use the "title" and "action" properties of the Link object to set the parameter name instead of hard-coding to "data".
This is part of a proposed solution to core-api#28
1 parent 1c1c680 commit 7147ec5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

openapi_codec/encode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import coreschema
22
from collections import OrderedDict
33
from coreapi.compat import urlparse
4-
from openapi_codec.utils import get_method, get_encoding, get_location, get_links_from_document
4+
from openapi_codec.utils import get_method, get_encoding, get_location, get_links_from_document, get_parameter_name
55

66

77
def generate_swagger_object(document):
@@ -193,8 +193,9 @@ def _get_parameters(link, encoding):
193193
parameters.append(parameter)
194194

195195
if properties:
196+
parameter_name = get_parameter_name(link)
196197
parameter = {
197-
'name': 'data',
198+
'name': parameter_name,
198199
'in': 'body',
199200
'schema': {
200201
'type': 'object',

openapi_codec/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def get_method(link):
3030
return method
3131

3232

33+
def get_parameter_name(link):
34+
return link.title.title() + link.action.title() + "Params"
35+
36+
3337
def get_encoding(link):
3438
encoding = link.encoding
3539
has_body = any([get_location(link, field) in ('form', 'body') for field in link.fields])

0 commit comments

Comments
 (0)