9
9
Schema ,
10
10
)
11
11
12
+ JSON_CONTENT_TYPE = "application/json"
13
+
12
14
13
15
def test_openapi_no_params ():
14
16
app = ApiGatewayResolver ()
15
17
16
18
@app .get ("/" )
17
19
def handler ():
18
- pass
20
+ raise NotImplementedError ()
19
21
20
- schema = app .get_openapi_schema (title = "Hello API" , version = "1.0.0" )
22
+ schema = app .get_openapi_schema ()
23
+ assert schema .info .title == "Powertools API"
24
+ assert schema .info .version == "1.0.0"
21
25
22
26
assert len (schema .paths .keys ()) == 1
23
27
assert "/" in schema .paths
@@ -33,8 +37,8 @@ def handler():
33
37
response = get .responses ["200" ]
34
38
assert response .description == "Success"
35
39
36
- assert "application/json" in response .content
37
- json_response = response .content ["application/json" ]
40
+ assert JSON_CONTENT_TYPE in response .content
41
+ json_response = response .content [JSON_CONTENT_TYPE ]
38
42
assert json_response .schema_ == Schema ()
39
43
assert not json_response .examples
40
44
assert not json_response .encoding
@@ -45,9 +49,11 @@ def test_openapi_with_scalar_params():
45
49
46
50
@app .get ("/users/<user_id>" )
47
51
def handler (user_id : str , include_extra : bool = False ):
48
- pass
52
+ raise NotImplementedError ()
49
53
50
- schema = app .get_openapi_schema (title = "Hello API" , version = "1.0.0" )
54
+ schema = app .get_openapi_schema (title = "My API" , version = "0.2.2" )
55
+ assert schema .info .title == "My API"
56
+ assert schema .info .version == "0.2.2"
51
57
52
58
assert len (schema .paths .keys ()) == 1
53
59
assert "/users/<user_id>" in schema .paths
@@ -86,13 +92,13 @@ def test_openapi_with_scalar_returns():
86
92
def handler () -> str :
87
93
return "Hello, world"
88
94
89
- schema = app .get_openapi_schema (title = "Hello API" , version = "1.0.0" )
95
+ schema = app .get_openapi_schema ()
90
96
assert len (schema .paths .keys ()) == 1
91
97
92
98
get = schema .paths ["/" ].get
93
99
assert get .parameters is None
94
100
95
- response = get .responses ["200" ].content ["application/json" ]
101
+ response = get .responses ["200" ].content [JSON_CONTENT_TYPE ]
96
102
assert response .schema_ .title == "Return"
97
103
assert response .schema_ .type == "string"
98
104
@@ -107,13 +113,13 @@ class User(BaseModel):
107
113
def handler () -> User :
108
114
return User (name = "Ruben Fonseca" )
109
115
110
- schema = app .get_openapi_schema (title = "Hello API" , version = "1.0.0" )
116
+ schema = app .get_openapi_schema ()
111
117
assert len (schema .paths .keys ()) == 1
112
118
113
119
get = schema .paths ["/" ].get
114
120
assert get .parameters is None
115
121
116
- response = get .responses ["200" ].content ["application/json" ]
122
+ response = get .responses ["200" ].content [JSON_CONTENT_TYPE ]
117
123
reference = response .schema_
118
124
assert reference .ref == "#/components/schemas/User"
119
125
@@ -135,13 +141,13 @@ class User:
135
141
def handler () -> User :
136
142
return User (name = "Ruben Fonseca" )
137
143
138
- schema = app .get_openapi_schema (title = "Hello API" , version = "1.0.0" )
144
+ schema = app .get_openapi_schema ()
139
145
assert len (schema .paths .keys ()) == 1
140
146
141
147
get = schema .paths ["/" ].get
142
148
assert get .parameters is None
143
149
144
- response = get .responses ["200" ].content ["application/json" ]
150
+ response = get .responses ["200" ].content [JSON_CONTENT_TYPE ]
145
151
reference = response .schema_
146
152
assert reference .ref == "#/components/schemas/User"
147
153
0 commit comments