Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept empty components property in Open Api Definition #2296

Merged
merged 2 commits into from
Jan 18, 2022
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
4 changes: 4 additions & 0 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ def _openapi_postprocess(self, definition_body):
):
if definition_body.get("securityDefinitions"):
components = definition_body.get("components", Py27Dict())
# In the previous line, the default value `Py27Dict()` will be only returned only if `components`
# property is not in definition_body dict, but if it exist, and its value is None, so None will be
# returned and not the default value. That is why the below line is required.
components = components if components else Py27Dict()
components["securitySchemes"] = definition_body["securityDefinitions"]
definition_body["components"] = components
del definition_body["securityDefinitions"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.handler
Runtime: nodejs12.x
ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
securityDefinitions: # 1 Add security definition
CognitoAuthorizer:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "cognito_user_pools"
x-amazon-apigateway-authorizer:
providerARNs:
- # userPool ARN
type: "cognito_user_pools"
paths:
"/{proxy+}":
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations
responses: { }
components:
schemas:
Error:
type: Object
properties:
message:
type: string
openapi: '3.0.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.handler
Runtime: nodejs12.x
ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
securityDefinitions: # 1 Add security definition
CognitoAuthorizer:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "cognito_user_pools"
x-amazon-apigateway-authorizer:
providerARNs:
- # userPool ARN
type: "cognito_user_pools"
paths:
"/{proxy+}":
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations
responses: { }
openapi: '3.0.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.handler
Runtime: nodejs12.x
ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
securityDefinitions: # 1 Add security definition
CognitoAuthorizer:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "cognito_user_pools"
x-amazon-apigateway-authorizer:
providerARNs:
- # userPool ARN
type: "cognito_user_pools"
paths:
"/{proxy+}":
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations
responses: { }
components:
openapi: '3.0.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"Resources": {
"GetHtmlFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "member_portal.zip"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"GetHtmlFunctionRole",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"GetHtmlFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"ExplicitApiDeployment195f5bf5d0": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350",
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Stage"
}
},
"ExplicitApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiDeployment195f5bf5d0"
},
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Prod"
}
},
"ExplicitApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/{proxy+}": {
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations"
}
},
"responses": {}
}
}
},
"openapi": "3.0.0",
"components": {
"securitySchemes": {
"CognitoAuthorizer": {
"x-amazon-apigateway-authtype": "cognito_user_pools",
"type": "apiKey",
"name": "Authorization",
"x-amazon-apigateway-authorizer": {
"providerARNs": [
null
],
"type": "cognito_user_pools"
},
"in": "header"
}
},
"schemas": {
"Error": {
"type": "Object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"Resources": {
"GetHtmlFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "member_portal.zip"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"GetHtmlFunctionRole",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"GetHtmlFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"ExplicitApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiDeployment407993a935"
},
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Prod"
}
},
"ExplicitApiDeployment407993a935": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64",
"RestApiId": {
"Ref": "ExplicitApi"
},
"StageName": "Stage"
}
},
"ExplicitApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/{proxy+}": {
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations"
}
},
"responses": {}
}
}
},
"openapi": "3.0.0",
"components": {
"securitySchemes": {
"CognitoAuthorizer": {
"x-amazon-apigateway-authtype": "cognito_user_pools",
"type": "apiKey",
"name": "Authorization",
"x-amazon-apigateway-authorizer": {
"providerARNs": [
null
],
"type": "cognito_user_pools"
},
"in": "header"
}
}
}
}
}
}
}
}
Loading