FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-openapi-codec/openapi_codec/__init__.py at master · aljp/python-openapi-codec · GitHub
aljp
/
python-openapi-codec
Public
forked from
core-api/python-openapi-codec
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-openapi-codec
/
openapi_codec
/
__init__.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (29 loc) · 1.12 KB
Breadcrumbs
python-openapi-codec
/
openapi_codec
/
__init__.py
Copy path
File metadata and controls
38 lines (29 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import
json
from
coreapi
.
codecs
.
base
import
BaseCodec
from
coreapi
.
compat
import
force_bytes
from
coreapi
.
document
import
Document
from
coreapi
.
exceptions
import
ParseError
from
openapi_codec
.
encode
import
generate_swagger_object
from
openapi_codec
.
decode
import
_parse_document
__version__
=
'1.3.1'
class
OpenAPICodec
(
BaseCodec
):
media_type
=
'application/openapi+json'
format
=
'openapi'
def
decode
(
self
,
bytes
,
**
options
):
"""
Takes a bytestring and returns a document.
"""
try
:
data
=
json
.
loads
(
bytes
.
decode
(
'utf-8'
))
except
ValueError
as
exc
:
raise
ParseError
(
'Malformed JSON. %s'
%
exc
)
base_url
=
options
.
get
(
'base_url'
)
doc
=
_parse_document
(
data
,
base_url
)
if
not
isinstance
(
doc
,
Document
):
raise
ParseError
(
'Top level node must be a document.'
)
return
doc
def
encode
(
self
,
document
,
**
options
):
if
not
isinstance
(
document
,
Document
):
raise
TypeError
(
'Expected a `coreapi.Document` instance'
)
data
=
generate_swagger_object
(
document
)
return
force_bytes
(
json
.
dumps
(
data
))
Back
|
FazBrowse Home
|
New Git URL