AWS::Serverless::Api Models only support object type
Description:
Defining api model with type other than object (specifically without a properties attribute) results in validation error.
SAM CLI, version 0.43.0
Steps to reproduce the issue:
- Define
Modelsproperty to include a model without theproperties(for example typearray) attribute like so:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Models:
MyModel:
items:
type: integer
type: array
title: MyModel
- Run
sam validate -t template.yaml
Observed result:
An exception is raised:
ValueError: Invalid input. Value for properties is required
Expected result:
Successful validation. Models support all types supported by json schema without requirement for properties.
It looks like SAM enforces having properties in the model here. Looks like we could update this section to remove this check.
So I tried removing these two lines and after that sam validate succeeded, however running sam deploy failed with this error.
Error: Failed to create changeset for the stack: model-test, ex: Waiter ChangeSetCreateComplete failed:
Waiter encountered a terminal failure state Status: FAILED.
Reason: Transform AWS::Serverless-2016-10-31 failed with: Internal transform failure.
Currently a workaround is to define a "dummy" properties attribute like this:
MyModel:
properties:
dummy: {}
items:
type: integer
type: array
title: MyModel
which produces this APIGW model:
{
"title" : "MyModel",
"properties" : { },
"type" : "array",
"items" : {
"type" : "integer"
}
}
The properties attribute is never used, as the type of the object is array, and APIGW validation works as expected.
@hurlenko yeah it looks like the ValueError that is being thrown when you run this locally isn't caught when it's run in the cloud, so it's returning an internal transform failure.
You would have to run sam deploy on a transformed version of the template in order for this to work; local changes to SAM are not reflected in the cloud version of SAM when you deploy a template.
Hi @keetonian, first time here ! :). I can work in this issue but need to ask something before: Why are we doing this post-validation step as we've just run it for the whole body ? Shouldn't we trust in open api's validation and remove both validations ?