8000 Comments · ndcolling/python-openapi-codec@6803b6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6803b6a

Browse files
committed
Comments
1 parent d6664e6 commit 6803b6a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

openapi_codec/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class OpenAPICodec(BaseCodec):
1515
media_type = "application/openapi+json"
1616
supports = ['encoding', 'decoding']
1717

18-
def load(self, bytes, base_url=None):
18+
def decode(self, bytes, **options):
1919
"""
2020
Takes a bytestring and returns a document.
2121
"""
@@ -24,12 +24,15 @@ def load(self, bytes, base_url=None):
2424
except ValueError as exc:
2525
raise ParseError('Malformed JSON. %s' % exc)
2626

27+
base_url = options.get('base_url')
2728
doc = _parse_document(data, base_url)
2829
if not isinstance(doc, Document):
2930
raise ParseError('Top level node must be a document.')
3031

3132
return doc
3233

33-
def dump(self, document, **kwargs):
34+
def encode(self, document, **options):
35+
if not isinstance(document, coreapi.Document):
36+
raise ValueError('Expected a `coreapi.Document` instance')
3437
data = generate_swagger_object(document)
3538
return force_bytes(json.dumps(data))

openapi_codec/encode.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def _get_parameters(link, encoding):
8080
location = get_location(link, field)
8181
if location == 'form':
8282
if encoding in ('multipart/form-data', 'application/x-www-form-urlencoded'):
83+
# 'formData' in swagger MUST be one of these media types.
8384
parameter = {
8485
'name': field.name,
8586
'required': field.required,
@@ -89,6 +90,8 @@ def _get_parameters(link, encoding):
8990
}
9091
parameters.append(parameter)
9192
else:
93+
# Expand coreapi fields with location='form' into a single swagger
94+
# parameter, with a schema containing multiple properties.
9295
schema_property = {
9396
'description': field.description
9497
}
@@ -133,13 +136,6 @@ def _get_parameters(link, encoding):
133136
return parameters
134137

135138

136-
def _get_in(link, field):
137-
in_location = get_location(link, field)
138-
if in_location == 'form':
139-
return 'formData'
140-
return in_location
141-
142-
143139
def _get_responses(link):
144140
"""
145141
Returns minimally acceptable responses object based

0 commit comments

Comments
 (0)
0