Skip to content

fix: allow Api model without properties #2709

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

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 0 additions & 3 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,6 @@ def add_models(self, models): # type: ignore[no-untyped-def]
if not model_type:
raise InvalidDocumentException([InvalidTemplateException("'Models' schema is missing 'type'.")])

if not model_properties:
raise InvalidDocumentException([InvalidTemplateException("'Models' schema is missing 'properties'.")])

self.definitions[model_name.lower()] = schema

def add_resource_policy(self, resource_policy, path, stage): # type: ignore[no-untyped-def]
Expand Down
11 changes: 11 additions & 0 deletions tests/translator/input/api_model_without_properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Models:
MyModel:
items:
type: integer
type: array
title: MyModel
50 changes: 50 additions & 0 deletions tests/translator/output/api_model_without_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"Resources": {
"MyApi": {
"Properties": {
"Body": {
"definitions": {
"mymodel": {
"items": {
"type": "integer"
},
"title": "MyModel",
"type": "array"
}
},
"info": {
"title": {
"Ref": "AWS::StackName"
},
"version": "1.0"
},
"paths": {},
"swagger": "2.0"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"MyApiDeployment49616beda5": {
"Properties": {
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"MyApiProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeployment49616beda5"
},
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Resources": {
"MyApi": {
"Properties": {
"Body": {
"definitions": {
"mymodel": {
"items": {
"type": "integer"
},
"title": "MyModel",
"type": "array"
}
},
"info": {
"title": {
"Ref": "AWS::StackName"
},
"version": "1.0"
},
"paths": {},
"swagger": "2.0"
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
]
},
"Parameters": {
"endpointConfigurationTypes": "REGIONAL"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"MyApiDeployment49616beda5": {
"Properties": {
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"MyApiProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeployment49616beda5"
},
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Resources": {
"MyApi": {
"Properties": {
"Body": {
"definitions": {
"mymodel": {
"items": {
"type": "integer"
},
"title": "MyModel",
"type": "array"
}
},
"info": {
"title": {
"Ref": "AWS::StackName"
},
"version": "1.0"
},
"paths": {},
"swagger": "2.0"
},
"EndpointConfiguration": {
"Types": [
"REGIONAL"
]
},
"Parameters": {
"endpointConfigurationTypes": "REGIONAL"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"MyApiDeployment49616beda5": {
"Properties": {
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"MyApiProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeployment49616beda5"
},
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}