@@ -32,6 +32,7 @@ def handler():
32
32
def test_openapi_top_level_security_missing ():
33
33
# GIVEN an APIGatewayRestResolver instance
34
34
app = APIGatewayRestResolver ()
35
+ app .enable_swagger ()
35
36
36
37
@app .get ("/" )
37
38
def handler ():
@@ -48,17 +49,14 @@ def handler():
48
49
def test_openapi_operation_security ():
49
50
# GIVEN an APIGatewayRestResolver instance
50
51
app = APIGatewayRestResolver ()
52
+ security_schemes = {"apiKey" : APIKey (name = "X-API-KEY" , description = "API Key" , in_ = APIKeyIn .header )}
51
53
52
54
@app .get ("/" , security = [{"apiKey" : []}])
53
55
def handler ():
54
56
raise NotImplementedError ()
55
57
56
58
# WHEN the get_openapi_schema method is called with security defined at the operation level
57
- schema = app .get_openapi_schema (
58
- security_schemes = {
59
- "apiKey" : APIKey (name = "X-API-KEY" , description = "API Key" , in_ = APIKeyIn .header ),
60
- },
61
- )
59
+ schema = app .get_openapi_schema (security_schemes = security_schemes )
62
60
63
61
# THEN the resulting schema should have security defined at the operation level, not the top level
64
62
top_level_security = schema .security
@@ -71,6 +69,7 @@ def test_openapi_operation_security_with_router():
71
69
# GIVEN an APIGatewayRestResolver instance with a Router
72
70
app = APIGatewayRestResolver ()
73
71
router = Router ()
72
+ security_schemes = {"apiKey" : APIKey (name = "X-API-KEY" , description = "API Key" , in_ = APIKeyIn .header )}
74
73
75
74
@router .get ("/" , security = [{"apiKey" : []}])
76
75
def handler ():
@@ -79,11 +78,7 @@ def handler():
79
78
app .include_router (router )
80
79
81
80
# WHEN the get_openapi_schema method is called with security defined at the operation level in the Router
82
- schema = app .get_openapi_schema (
83
- security_schemes = {
84
- "apiKey" : APIKey (name = "X-API-KEY" , description = "API Key" , in_ = APIKeyIn .header ),
85
- },
86
- )
81
+ schema = app .get_openapi_schema (security_schemes = security_schemes )
87
82
88
83
# THEN the resulting schema should have security defined at the operation level
89
84
top_level_security = schema .security
0 commit comments