Skip to content

Commit

Permalink
fix: allow Api model without properties (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffa authored Dec 7, 2022
1 parent 0cae2bb commit a82a19f
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 10 deletions.
4 changes: 0 additions & 4 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,14 +855,10 @@ def add_models(self, models): # type: ignore[no-untyped-def]
for model_name, schema in models.items():

model_type = schema.get("type")
model_properties = schema.get("properties")

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
6 changes: 0 additions & 6 deletions tests/swagger/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,6 @@ def test_must_fail_without_type_in_model(self):
with self.assertRaises(InvalidDocumentException):
self.editor.add_models(models)

def test_must_fail_without_properties_in_model(self):
models = {"User": {"type": "object"}}

with self.assertRaises(InvalidDocumentException):
self.editor.add_models(models)


class TestSwaggerEditor_add_request_model_to_method(TestCase):
def setUp(self):
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"
}
}
}
58 changes: 58 additions & 0 deletions tests/translator/output/aws-cn/api_model_without_properties.json
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"
}
}
}

0 comments on commit a82a19f

Please sign in to comment.