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

AWS::Serverless::Api Models only support object type #1559

Open
hurlenko opened this issue Apr 14, 2020 · 4 comments
Open

AWS::Serverless::Api Models only support object type #1559

hurlenko opened this issue Apr 14, 2020 · 4 comments

Comments

@hurlenko
Copy link

@hurlenko hurlenko commented Apr 14, 2020

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:

  1. Define Models property to include a model without the properties (for example type array) 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
  1. 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.

@keetonian
Copy link
Contributor

@keetonian keetonian commented Apr 17, 2020

It looks like SAM enforces having properties in the model here. Looks like we could update this section to remove this check.

@hurlenko
Copy link
Author

@hurlenko hurlenko commented Apr 18, 2020

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: 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.

@keetonian
Copy link
Contributor

@keetonian keetonian commented Apr 21, 2020

@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.

@gmcrocetti
Copy link

@gmcrocetti gmcrocetti commented Sep 12, 2020

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.