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

Validate swagger path item objects #2251

Merged
merged 1 commit into from
Nov 29, 2021
Merged

Conversation

aahung
Copy link
Contributor

@aahung aahung commented Nov 29, 2021

Issue #, if available:

Description of changes:

Add validation of path item objects when creating the SwaggerEditor object.

Possible concerns:

What if it breaks some existing template despite they are invalid, customers are still using them?

I just did a test with CFN, turns out even we don't do validation ourselves, CFN/Api Gateway will fail.

Tested templates:

# Failed with rollback: Invalid OpenAPI input
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ApiWithInvalidPath:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: 2.0
        paths:
          /foo: ""
# Failed with rollback: Invalid OpenAPI input
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ApiWithInvalidPath:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: 2.0
        paths:
          /foo: "some string"
# Failed with rollback: Invalid OpenAPI input
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ApiWithInvalidPath:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: 2.0
        paths:
          /foo: 123
# Failed during creating changeset
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ApiWithInvalidPath:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: 2.0
        paths:
          /foo:
# Failed during creating changeset
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ApiWithInvalidPath:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: 2.0
        paths:
          /foo: null

Description of how you validated changes:

Checklist:

  • Add/update tests using:
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aahung aahung force-pushed the validate-null-path branch 2 times, most recently from cc12a2c to be4ccde Compare November 29, 2021 20:28
@aahung aahung marked this pull request as ready for review November 29, 2021 20:29
Copy link
Contributor

@torresxb1 torresxb1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@aahung aahung merged commit 6504848 into aws:develop Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants