Skip to content

Commit a82a19f

Browse files
authored
fix: allow Api model without properties (#2709)
1 parent 0cae2bb commit a82a19f

File tree

6 files changed

+177
-10
lines changed

6 files changed

+177
-10
lines changed

samtranslator/swagger/swagger.py

-4
Original file line numberDiff line numberDiff line change
@@ -855,14 +855,10 @@ def add_models(self, models): # type: ignore[no-untyped-def]
855855
for model_name, schema in models.items():
856856

857857
model_type = schema.get("type")
858-
model_properties = schema.get("properties")
859858

860859
if not model_type:
861860
raise InvalidDocumentException([InvalidTemplateException("'Models' schema is missing 'type'.")])
862861

863-
if not model_properties:
864-
raise InvalidDocumentException([InvalidTemplateException("'Models' schema is missing 'properties'.")])
865-
866862
self.definitions[model_name.lower()] = schema
867863

868864
def add_resource_policy(self, resource_policy, path, stage): # type: ignore[no-untyped-def]

tests/swagger/test_swagger.py

-6
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,6 @@ def test_must_fail_without_type_in_model(self):
692692
with self.assertRaises(InvalidDocumentException):
693693
self.editor.add_models(models)
694694

695-
def test_must_fail_without_properties_in_model(self):
696-
models = {"User": {"type": "object"}}
697-
698-
with self.assertRaises(InvalidDocumentException):
699-
self.editor.add_models(models)
700-
701695

702696
class TestSwaggerEditor_add_request_model_to_method(TestCase):
703697
def setUp(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Resources:
2+
MyApi:
3+
Type: AWS::Serverless::Api
4+
Properties:
5+
StageName: Prod
6+
Models:
7+
MyModel:
8+
items:
9+
type: integer
10+
type: array
11+
title: MyModel
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Resources": {
3+
"MyApi": {
4+
"Properties": {
5+
"Body": {
6+
"definitions": {
7+
"mymodel": {
8+
"items": {
9+
"type": "integer"
10+
},
11+
"title": "MyModel",
12+
"type": "array"
13+
}
14+
},
15+
"info": {
16+
"title": {
17+
"Ref": "AWS::StackName"
18+
},
19+
"version": "1.0"
20+
},
21+
"paths": {},
22+
"swagger": "2.0"
23+
}
24+
},
25+
"Type": "AWS::ApiGateway::RestApi"
26+
},
27+
"MyApiDeployment49616beda5": {
28+
"Properties": {
29+
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
30+
"RestApiId": {
31+
"Ref": "MyApi"
32+
},
33+
"StageName": "Stage"
34+
},
35+
"Type": "AWS::ApiGateway::Deployment"
36+
},
37+
"MyApiProdStage": {
38+
"Properties": {
39+
"DeploymentId": {
40+
"Ref": "MyApiDeployment49616beda5"
41+
},
42+
"RestApiId": {
43+
"Ref": "MyApi"
44+
},
45+
"StageName": "Prod"
46+
},
47+
"Type": "AWS::ApiGateway::Stage"
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"Resources": {
3+
"MyApi": {
4+
"Properties": {
5+
"Body": {
6+
"definitions": {
7+
"mymodel": {
8+
"items": {
9+
"type": "integer"
10+
},
11+
"title": "MyModel",
12+
"type": "array"
13+
}
14+
},
15+
"info": {
16+
"title": {
17+
"Ref": "AWS::StackName"
18+
},
19+
"version": "1.0"
20+
},
21+
"paths": {},
22+
"swagger": "2.0"
23+
},
24+
"EndpointConfiguration": {
25+
"Types": [
26+
"REGIONAL"
27+
]
28+
},
29+
"Parameters": {
30+
"endpointConfigurationTypes": "REGIONAL"
31+
}
32+
},
33+
"Type": "AWS::ApiGateway::RestApi"
34+
},
35+
"MyApiDeployment49616beda5": {
36+
"Properties": {
37+
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
38+
"RestApiId": {
39+
"Ref": "MyApi"
40+
},
41+
"StageName": "Stage"
42+
},
43+
"Type": "AWS::ApiGateway::Deployment"
44+
},
45+
"MyApiProdStage": {
46+
"Properties": {
47+
"DeploymentId": {
48+
"Ref": "MyApiDeployment49616beda5"
49+
},
50+
"RestApiId": {
51+
"Ref": "MyApi"
52+
},
53+
"StageName": "Prod"
54+
},
55+
"Type": "AWS::ApiGateway::Stage"
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"Resources": {
3+
"MyApi": {
4+
"Properties": {
5+
"Body": {
6+
"definitions": {
7+
"mymodel": {
8+
"items": {
9+
"type": "integer"
10+
},
11+
"title": "MyModel",
12+
"type": "array"
13+
}
14+
},
15+
"info": {
16+
"title": {
17+
"Ref": "AWS::StackName"
18+
},
19+
"version": "1.0"
20+
},
21+
"paths": {},
22+
"swagger": "2.0"
23+
},
24+
"EndpointConfiguration": {
25+
"Types": [
26+
"REGIONAL"
27+
]
28+
},
29+
"Parameters": {
30+
"endpointConfigurationTypes": "REGIONAL"
31+
}
32+
},
33+
"Type": "AWS::ApiGateway::RestApi"
34+
},
35+
"MyApiDeployment49616beda5": {
36+
"Properties": {
37+
"Description": "RestApi deployment id: 49616beda518d56ac1dbce9c34f09ccca4862616",
38+
"RestApiId": {
39+
"Ref": "MyApi"
40+
},
41+
"StageName": "Stage"
42+
},
43+
"Type": "AWS::ApiGateway::Deployment"
44+
},
45+
"MyApiProdStage": {
46+
"Properties": {
47+
"DeploymentId": {
48+
"Ref": "MyApiDeployment49616beda5"
49+
},
50+
"RestApiId": {
51+
"Ref": "MyApi"
52+
},
53+
"StageName": "Prod"
54+
},
55+
"Type": "AWS::ApiGateway::Stage"
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)