12
12
13
13
14
14
def test_openapi_extension_root_level ():
15
+ # GIVEN an APIGatewayRestResolver instance
15
16
app = APIGatewayRestResolver ()
16
17
17
18
cors_config = {
18
19
"maxAge" : 0 ,
19
20
"allowCredentials" : False ,
20
21
}
21
22
23
+ # WHEN we get the OpenAPI JSON schema with CORS extension in the Root Level
22
24
schema = json .loads (
23
25
app .get_openapi_json_schema (
24
26
openapi_extensions = {"x-amazon-apigateway-cors" : cors_config },
25
27
),
26
28
)
27
29
30
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-cors" extension
28
31
assert "x-amazon-apigateway-cors" in schema
29
32
assert schema ["x-amazon-apigateway-cors" ] == cors_config
30
33
31
34
32
35
def test_openapi_extension_server_level ():
36
+ # GIVEN an APIGatewayRestResolver instance
33
37
app = APIGatewayRestResolver ()
34
38
35
39
endpoint_config = {
@@ -42,6 +46,7 @@ def test_openapi_extension_server_level():
42
46
"description" : "Example website" ,
43
47
}
44
48
49
+ # WHEN we get the OpenAPI JSON schema with a server-level openapi extension
45
50
schema = json .loads (
46
51
app .get_openapi_json_schema (
47
52
title = "Hello API" ,
@@ -57,11 +62,13 @@ def test_openapi_extension_server_level():
57
62
),
58
63
)
59
64
65
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-endpoint-configuration" at the server level
60
66
assert "x-amazon-apigateway-endpoint-configuration" in schema ["servers" ][0 ]
61
67
assert schema ["servers" ][0 ]["x-amazon-apigateway-endpoint-configuration" ] == endpoint_config
62
68
63
69
64
70
def test_openapi_extension_security_scheme_level_with_api_key ():
71
+ # GIVEN an APIGatewayRestResolver instance
65
72
app = APIGatewayRestResolver ()
66
73
67
74
authorizer_config = {
@@ -76,6 +83,7 @@ def test_openapi_extension_security_scheme_level_with_api_key():
76
83
"in_" : APIKeyIn .header ,
77
84
}
78
85
86
+ # WHEN we get the OpenAPI JSON schema with a security scheme-level extension for a custom auth
79
87
schema = json .loads (
80
88
app .get_openapi_json_schema (
81
89
security_schemes = {
@@ -90,12 +98,14 @@ def test_openapi_extension_security_scheme_level_with_api_key():
90
98
),
91
99
)
92
100
101
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-authtype" extension at the security scheme level
93
102
assert "x-amazon-apigateway-authtype" in schema ["components" ]["securitySchemes" ]["apiKey" ]
94
103
assert schema ["components" ]["securitySchemes" ]["apiKey" ]["x-amazon-apigateway-authtype" ] == "custom"
95
104
assert schema ["components" ]["securitySchemes" ]["apiKey" ]["x-amazon-apigateway-authorizer" ] == authorizer_config
96
105
97
106
98
107
def test_openapi_extension_security_scheme_level_with_oauth2 ():
108
+ # GIVEN an APIGatewayRestResolver instance
99
109
app = APIGatewayRestResolver ()
100
110
101
111
authorizer_config = {
@@ -115,6 +125,7 @@ def test_openapi_extension_security_scheme_level_with_oauth2():
115
125
),
116
126
}
117
127
128
+ # WHEN we get the OpenAPI JSON schema with a security scheme-level extension for a custom auth
118
129
schema = json .loads (
119
130
app .get_openapi_json_schema (
120
131
security_schemes = {
@@ -128,19 +139,24 @@ def test_openapi_extension_security_scheme_level_with_oauth2():
128
139
),
129
140
)
130
141
142
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-authorizer" extension at the security scheme level
131
143
assert "x-amazon-apigateway-authorizer" in schema ["components" ]["securitySchemes" ]["oauth2" ]
132
144
assert schema ["components" ]["securitySchemes" ]["oauth2" ]["x-amazon-apigateway-authorizer" ] == authorizer_config
133
145
134
146
135
147
def test_openapi_extension_operation_level (openapi_extension_integration_detail ):
148
+ # GIVEN an APIGatewayRestResolver instance
136
149
app = APIGatewayRestResolver ()
137
150
151
+ # WHEN we define an integration extension at operation level
152
+ # AND get the schema
138
153
@app .get ("/test" , openapi_extensions = {"x-amazon-apigateway-integration" : openapi_extension_integration_detail })
139
154
def lambda_handler ():
140
155
pass
141
156
142
157
schema = json .loads (app .get_openapi_json_schema ())
143
158
159
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-integration" extension at the operation level
144
160
assert "x-amazon-apigateway-integration" in schema ["paths" ]["/test" ]["get" ]
145
161
assert schema ["paths" ]["/test" ]["get" ]["x-amazon-apigateway-integration" ] == openapi_extension_integration_detail
146
162
@@ -149,8 +165,11 @@ def test_openapi_extension_operation_level_multiple_paths(
149
165
openapi_extension_integration_detail ,
150
166
openapi_extension_validator_detail ,
151
167
):
168
+ # GIVEN an APIGatewayRestResolver instance
152
169
app = APIGatewayRestResolver ()
153
170
171
+ # WHEN we define multiple routes with integration extension at operation level
172
+ # AND get the schema
154
173
@app .get ("/test" , openapi_extensions = {"x-amazon-apigateway-integration" : openapi_extension_integration_detail })
155
174
def lambda_handler_get ():
156
175
pass
@@ -161,6 +180,7 @@ def lambda_handler_post():
161
180
162
181
schema = json .loads (app .get_openapi_json_schema ())
163
182
183
+ # THEN each route must contain only your extension
164
184
assert "x-amazon-apigateway-integration" in schema ["paths" ]["/test" ]["get" ]
165
185
assert schema ["paths" ]["/test" ]["get" ]["x-amazon-apigateway-integration" ] == openapi_extension_integration_detail
166
186
@@ -172,9 +192,12 @@ def lambda_handler_post():
172
192
173
193
174
194
def test_openapi_extension_operation_level_with_router (openapi_extension_integration_detail ):
195
+ # GIVEN an APIGatewayRestResolver and Router instance
175
196
app = APIGatewayRestResolver ()
176
197
router = Router ()
177
198
199
+ # WHEN we define an integration extension at operation level using Router
200
+ # AND get the schema
178
201
@router .get ("/test" , openapi_extensions = {"x-amazon-apigateway-integration" : openapi_extension_integration_detail })
179
202
def lambda_handler ():
180
203
pass
@@ -183,6 +206,7 @@ def lambda_handler():
183
206
184
207
schema = json .loads (app .get_openapi_json_schema ())
185
208
209
+ # THEN the OpenAPI schema must contain the "x-amazon-apigateway-integration" extension at the operation level
186
210
assert "x-amazon-apigateway-integration" in schema ["paths" ]["/test" ]["get" ]
187
211
assert schema ["paths" ]["/test" ]["get" ]["x-amazon-apigateway-integration" ] == openapi_extension_integration_detail
188
212
@@ -191,9 +215,12 @@ def test_openapi_extension_operation_level_multiple_paths_with_router(
191
215
openapi_extension_integration_detail ,
192
216
openapi_extension_validator_detail ,
193
217
):
218
+ # GIVEN an APIGatewayRestResolver and Router instance
194
219
app = APIGatewayRestResolver ()
195
220
router = Router ()
196
221
222
+ # WHEN we define multiple routes using extensions at operation level using Router
223
+ # AND get the schema
197
224
@router .get ("/test" , openapi_extensions = {"x-amazon-apigateway-integration" : openapi_extension_integration_detail })
198
225
def lambda_handler_get ():
199
226
pass
@@ -209,6 +236,7 @@ def lambda_handler_post():
209
236
210
237
schema = json .loads (app .get_openapi_json_schema ())
211
238
239
+ # THEN each route must contain only your extension
212
240
assert "x-amazon-apigateway-integration" in schema ["paths" ]["/test" ]["get" ]
213
241
assert schema ["paths" ]["/test" ]["get" ]["x-amazon-apigateway-integration" ] == openapi_extension_integration_detail
214
242
0 commit comments