…thorizer default
OpenApiEditor.add_auth_to_method defaulted an unset AuthorizationScopes to
[], then _set_method_authorizer checked it with `if authorization_scopes:`.
Since [] is falsy, this couldn't distinguish "not set" from an explicit
empty-list override, so a method-level `AuthorizationScopes: []` (meant to
require no scopes, overriding the authorizer's default) was silently
ignored and the authorizer's default AuthorizationScopes were enforced
instead.
SwaggerEditor's equivalent REST API code path (swagger.py) already gets
this right by using None as the "not set" sentinel and an `is not None`
check. This applies the same fix to OpenApiEditor so HTTP APIs behave
consistently with REST APIs, and also aligns the authorizer-presence
check (`authorizers.get(authorizer_name) is not None`) with swagger.py's
pattern.
Fixes aws#3979
Summary
Fixes #3979.
For AWS::Serverless::HttpApi, an event/function-level Auth.AuthorizationScopes: [] is meant to override the named authorizer's default AuthorizationScopes, requiring no scopes for that method — this already works correctly for AWS::Serverless::Api (REST APIs).
OpenApiEditor.add_auth_to_method (samtranslator/open_api/open_api.py) defaulted an unset AuthorizationScopes to []:
_set_method_authorizer then checked it with if authorization_scopes: — since [] is falsy, this is indistinguishable from "not set," so the explicit override was silently dropped and the authorizer's default scopes were enforced instead. This means requests the template author intended to allow without those scopes get rejected by API Gateway.
SwaggerEditor's equivalent REST API code path (samtranslator/swagger/swagger.py) already handles this correctly — it uses None as the "not set" sentinel (auth.get("AuthorizationScopes"), no default) and checks is not None. This PR applies the identical fix to OpenApiEditor, and also aligns the authorizer-presence check (authorizers.get(authorizer_name) is not None) with swagger.py's pattern, replacing an unguarded authorizers[authorizer_name] dict-subscript.
Test plan