Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samtranslator/open_api/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, doc):

self._doc = copy.deepcopy(doc)
self.paths = self._doc["paths"]
self.security_schemes = self._doc.get("securitySchemes", {})
self.security_schemes = self._doc.get("components", {}).get("securitySchemes", {})
self.definitions = self._doc.get('definitions', {})

def get_path(self, path):
Expand Down Expand Up @@ -346,7 +346,8 @@ def openapi(self):
self._doc["paths"] = self.paths

if self.security_schemes:
self._doc["securitySchemes"] = self.security_schemes
self._doc.setdefault("components", {})
self._doc["components"]["securitySchemes"] = self.security_schemes

return copy.deepcopy(self._doc)

Expand Down
41 changes: 21 additions & 20 deletions tests/translator/input/http_api_existing_openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,24 @@ Resources:
- scope4
responses: {}
openapi: 3.0.1
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
components:
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
41 changes: 21 additions & 20 deletions tests/translator/input/http_api_existing_openapi_conditions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,24 @@ Resources:
- scope4
responses: {}
openapi: 3.0.1
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
components:
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
64 changes: 34 additions & 30 deletions tests/translator/output/aws-cn/explicit_http_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,30 @@
}
}
},
"openapi": "3.0.1",
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
}
}
}
}
}
},
"openapi": "3.0.1"
}
}
},
"HttpApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -136,6 +135,9 @@
}
]
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
Expand Down Expand Up @@ -198,24 +200,26 @@
}
}
},
"openapi": "3.0.1",
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
}
}
}
}
}
},
"openapi": "3.0.1"
}
}
}
}
}
}
62 changes: 32 additions & 30 deletions tests/translator/output/aws-cn/http_api_existing_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
"HttpApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -77,6 +73,10 @@
}
]
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess"
],
"Tags": [
{
"Value": "SAM",
Expand Down Expand Up @@ -180,32 +180,34 @@
}
}
},
"securitySchemes": {
"oauth2Auth": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
"components": {
"securitySchemes": {
"oauth2Auth": {
"type": "oauth2",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
}
}
},
"OpenIdAuth": {
"type": "openIdConnect",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
},
"openIdConnectUrl": "https://www.example.com/v1/connect"
}
}
},
"OpenIdAuth": {
"type": "openIdConnect",
"x-amazon-apigateway-authorizer": {
"identitySource": "$request.querystring.param",
"type": "jwt",
"jwtConfiguration": {
"audience": [
"MyApi"
],
"issuer": "https://www.example.com/v1/connect/oidc"
},
"openIdConnectUrl": "https://www.example.com/v1/connect"
}
}
},
Expand All @@ -214,4 +216,4 @@
}
}
}
}
}
Loading