-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Swagger api operation simple validation #2023
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
26c9ca7
raise invalid document error in case of invalid method definition of …
elbayaaa 9cac7bb
raise invalid document error in case of invalid swagger API operation…
elbayaaa 7f7949e
UT
elbayaaa 3ab1a3f
typo
elbayaaa 1f9af7f
remove the parameters section from UT
elbayaaa a60d595
remove summary and description properties from UT
elbayaaa 1556f3d
Revert "remove summary and description properties from UT"
elbayaaa eed8524
typo
elbayaaa 777e634
Revert "typo"
elbayaaa 9719bb5
Revert "Revert "remove summary and description properties from UT""
elbayaaa 8de50f4
Merge branch 'develop' into swagger_api_operation_validation
moelasmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/translator/input/error_api_with_usage_plan_invalid_path_method.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Resources: | ||
| ApiWithInvalidPathMethod: | ||
| Type: AWS::Serverless::Api | ||
| Properties: | ||
| Auth: | ||
| ApiKeyRequired: true | ||
| UsagePlan: | ||
| CreateUP: NONE | ||
| StageName: Prod | ||
| Cors: "'*'" | ||
| DefinitionBody: | ||
| swagger: 2.0 | ||
| paths: | ||
| /foo: | ||
| get: "Any non dict value" |
3 changes: 3 additions & 0 deletions
3
tests/translator/output/error_api_with_usage_plan_invalid_path_method.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Invalid swagger API operation definition: Any non dict value" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to match the OpenAPI 3.0. Looking at references, this class seems to be specific to Rest APIs. Rest APIs support both OpenAPI 2.0 and 3.0: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html
I think we may need to think deeper about this and the recent revert: #2021 as a swagger validation overhaul.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a block-list while #2021 was an allow-list. I mean, we know as a fact that
["parameters", "summary", "description", "$ref", "servers"]are not API operations (HTTP methods)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe asking this a different way. If a customer is using OpenAPI 2.0 and specifies "servers" in the path object, should SAM fail with this being invalid? I know this just ignores the values and moves on, but not sure where we should fail this.
If SAM doesn't fail in the case above, then API Gateway should reject it. Which could be enough, just poking at this to see if we really need or want to do these deeper level of validation or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you asking whether we should validate that the API definition complies with the OpenApi specification or not?
If so, I think this is not the responsibility of SAM. Here, we are trying to do our best to raise 4xx error instead of 5xx when applicable. So, if the API definition is invalid but it doesn't cause SAM to fail, I believe it shouldn't be a concern for SAM. Agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed this was in part validation we do.
Your reasoning makes sense to me.