FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi-python-client/openapi_python_client/parser/responses.py at main · ramnes/openapi-python-client · GitHub
ramnes
openapi-python-client
Repository navigation
Code
Pull requests
10
(10)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi-python-client
/
openapi_python_client
/
parser
/
responses.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (57 loc) · 2.13 KB
Breadcrumbs
openapi-python-client
/
openapi_python_client
/
parser
/
responses.py
Copy path
File metadata and controls
75 lines (57 loc) · 2.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
__all__
=
[
"Response"
,
"response_from_data"
]
from
typing
import
Tuple
,
Union
import
attr
from
..
import
schema
as
oai
from
.
errors
import
ParseError
,
PropertyError
from
.
properties
import
NoneProperty
,
Property
,
Schemas
,
property_from_data
@
attr
.
s
(
auto_attribs
=
True
,
frozen
=
True
)
class
Response
:
""" Describes a single response for an endpoint """
status_code
:
int
prop
:
Property
source
:
str
_SOURCE_BY_CONTENT_TYPE
=
{
"application/json"
:
"response.json()"
,
"application/vnd.api+json"
:
"response.json()"
,
"application/octet-stream"
:
"response.content"
,
"text/html"
:
"response.text"
,
}
def
empty_response
(
status_code
:
int
,
response_name
:
str
)
->
Response
:
return
Response
(
status_code
=
status_code
,
prop
=
NoneProperty
(
name
=
response_name
,
default
=
None
,
nullable
=
False
,
required
=
True
),
source
=
"None"
,
)
def
response_from_data
(
*
,
status_code
:
int
,
data
:
Union
[
oai
.
Response
,
oai
.
Reference
],
schemas
:
Schemas
,
parent_name
:
str
)
->
Tuple
[
Union
[
Response
,
ParseError
],
Schemas
]:
""" Generate a Response from the OpenAPI dictionary representation of it """
response_name
=
f"response_
{
status_code
}
"
if
isinstance
(
data
,
oai
.
Reference
)
or
data
.
content
is
None
:
return
(
empty_response
(
status_code
,
response_name
),
schemas
,
)
content
=
data
.
content
for
content_type
,
media_type
in
content
.
items
():
if
content_type
in
_SOURCE_BY_CONTENT_TYPE
:
source
=
_SOURCE_BY_CONTENT_TYPE
[
content_type
]
schema_data
=
media_type
.
media_type_schema
break
else
:
return
ParseError
(
data
=
data
,
detail
=
f"Unsupported content_type
{
content
}
"
),
schemas
if
schema_data
is
None
:
return
(
empty_response
(
status_code
,
response_name
),
schemas
,
)
prop
,
schemas
=
property_from_data
(
name
=
response_name
,
required
=
True
,
data
=
schema_data
,
schemas
=
schemas
,
parent_name
=
parent_name
,
)
if
isinstance
(
prop
,
PropertyError
):
return
prop
,
schemas
return
Response
(
status_code
=
status_code
,
prop
=
prop
,
source
=
source
),
schemas
Back
|
FazBrowse Home
|
New Git URL