FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-openapi-codec/openapi_codec/utils.py at master · dd/python-openapi-codec · GitHub
dd
/
python-openapi-codec
Public
forked from
core-api/python-openapi-codec
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
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
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (42 loc) · 1.33 KB
Breadcrumbs
python-openapi-codec
/
openapi_codec
/
utils.py
Copy path
File metadata and controls
50 lines (42 loc) · 1.33 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
39
40
41
42
43
44
45
46
47
48
49
50
def
link_sorting_key
(
link_item
):
keys
,
link
=
link_item
action_priority
=
{
''
:
0
,
'get'
:
0
,
'post'
:
1
,
'put'
:
2
,
'patch'
:
3
,
'delete'
:
4
}.
get
(
link
.
action
,
5
)
return
(
link
.
url
,
action_priority
)
def
get_links_from_document
(
node
,
keys
=
()):
links
=
[]
for
key
,
link
in
getattr
(
node
,
'links'
, {}).
items
():
# Get all the resources at this level
index
=
keys
+
(
key
,)
links
.
append
((
index
,
link
))
for
key
,
child
in
getattr
(
node
,
'data'
, {}).
items
():
# Descend into any nested structures.
index
=
keys
+
(
key
,)
links
.
extend
(
get_links_from_document
(
child
,
index
))
return
sorted
(
links
,
key
=
link_sorting_key
)
def
get_method
(
link
):
method
=
link
.
action
.
lower
()
if
not
method
:
method
=
'get'
return
method
def
get_encoding
(
link
):
encoding
=
link
.
encoding
has_body
=
any
([
get_location
(
link
,
field
)
in
(
'form'
,
'body'
)
for
field
in
link
.
fields
])
if
not
encoding
and
has_body
:
encoding
=
'application/json'
elif
encoding
and
not
has_body
:
encoding
=
''
return
encoding
def
get_location
(
link
,
field
):
location
=
field
.
location
if
not
location
:
if
get_method
(
link
)
in
(
'get'
,
'delete'
):
location
=
'query'
else
:
location
=
'form'
return
location
Back
|
FazBrowse Home
|
New Git URL