You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sam validate expects DefinitionBody or DefinitionUri to be set #803
Since the Default Definition Body feature, SAM provides a default DefinitionBody if neither a DefinitionBody or DefinitionUri is set on a AWS::Serverless:Api resource.
SAM CLI still expects DefinitionBody or DefinitionUri to be set in the validation workflow as found here. This assumption should be fixed (check for and replace DefinitionUri with a S3 location if it exists, otherwise do nothing).
Template provided at '...examples/2016-10-31/api_cognito_auth/template.yaml' was invalid SAM Template.
Error: [InvalidResourceException('MyApi', "Cors works only with inline Swagger specified in 'DefinitionBody' property")] ('MyApi', "Cors works only with inline Swagger specified in 'DefinitionBody' property")
Expected result:
Validation should succeed
Output of sam --version:
0.7.0, 0.8.0, 0.9.0
Reacted by jhappoldt, Daryl Peters, Chris Owens, Elver Loho, Erico Fusco, John Tims, Jair Trejo, Ednei Oliveira, mafesio, maaya ishida and 38 more
Are there any updates? Not being able to run validate and/or cfn-lint really makes automated CI/CD difficult
Reacted by Gavin Cornwell, Henok Tadesse, jkoshkarev, Richard O'flynn, Jack McGuire, Sangho Na, Rudolf Potucek, Mahdi Azarboon, astroanu, Bryan McKinley, Ph.D. and 1 more
@jfuss 'sam validate' seems to still be broken if using Fn::Transform and AWS::Include to reference and include an OpenAPI definition in a separate file while having a Globals -> Api -> Cors config in the SAM template.
sam validate
Template provided at '<my_path>/template.yaml' was invalid SAM Template.
Error: [InvalidResourceException('MyApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid Swagger")] ('MyApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid Swagger")
If I comment out my global cors config in my SAM template then validation works fine.
Reacted by Mo Kamioner, Andrew Fittz, Afzal Shahul Hameed, Michael Richardson, Felipe Marinho, Toby Saunders and ecoms-ye
ApiGatewayHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
# DefinitionUri: api/swagger.yaml # this does not work and seems to be a bug in AWS SAM
DefinitionBody:
openapi: "3.0.1" # workaround to get `sam validate` to work
paths: # workaround to get `sam validate` to work
/foo: bar # workaround to get `sam validate` to work
Fn::Transform:
Name: AWS::Include
Parameters:
Location: src/api/swagger.yaml
@julianste I've moved to SAM nightlies (1.21.1) to see if it was resolved there. I tried your 3 workaround lines, but got another error. Seems it's not happy with that incomplete definition.
if definition_body.get("paths").get(path).get("options"):
AttributeError: 'str' object has no attribute 'get'
@julianste I've moved to SAM nightlies (1.21.1) to see if it was resolved there. I tried your 3 workaround lines, but got another error. Seems it's not happy with that incomplete definition.
if definition_body.get("paths").get(path).get("options"):
AttributeError: 'str' object has no attribute 'get'
@rainabba my workaround probably just works for AWS::Serverless::HttpApi. Maybe insert some dummy dict containing options?
EDIT: Something like this seems to satisfy sam validate but I'm not sure about any other implications...
Type: AWS::Serverless::Api
Properties:
# DefinitionUri: api/swagger.yaml # this does not work and seems to be a bug in AWS SAM
DefinitionBody:
openapi: "3.0.1" # workaround to get `sam validate` to work
paths: # workaround to get `sam validate` to work
/foo:
options: {} # workaround to get `sam validate` to work
Fn::Transform:
Name: AWS::Include
Parameters:
Location: src/api/swagger.yaml
Reacted by Michael Richardson and ranxu-littledriver
@julianste@rainabba I have this working locally. The fix is to get the validator to detect the Transform->Include->Location pattern and replace the DefinitionBody with the contents of the yaml file itself during validation.
The workaround of copying contents of the api definition swagger file and pasting them exactly as they are under "DefinitionBody:" works. Thank you!
However, this is not a practical solution and a very error-prone one. @jfuss I do not think this ticket should be kept closed, the issue is still there.
I see this same issue in SAM CLI version 1.61.0, it looks like the PR #3882 was never merged. Are there any plans to fix this?
@cortexcompiler I ran out of capacity to make all the required changes that came up in the fix PR.
If this is important to you I can try and revive the PR when I have time.
problem still persists on version 1.81.0
error message Error: [InvalidResourceException('Api', "Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition.")] ('Api', "Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition.")
is still beeing displayed erroneously even after passing correctly
I am getting this error "Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition" when using Fn::Transform on my OAS3 file and defining an IP whitelist; looks to be related to this issue and #3041. The deploy is successful if I skip sam validate.
Activity
aetherical commentedon May 20, 2019
Are there any updates? Not being able to run validate and/or cfn-lint really makes automated CI/CD difficult
jackmcguire1 commentedon Jun 7, 2019
please someone, work on this <3
rudpot commentedon Jul 1, 2019
Still seeing this with sam 0.16.1 please fix
jfuss commentedon Jul 1, 2019
@jackmcguire1 or @rudpot Either of you want to take a stab at a fix?
azarboon commentedon Jul 25, 2019
yes I have this problem too and this is annoying. Having Cognito in my template, sam validate becomes useless.
LennyDuan commentedon Jul 25, 2019
Still have this issue, please fix it!
jfuss commentedon Sep 17, 2019
Release in v0.21.0.
Closing
paulsson-cs commentedon Oct 17, 2019
@jfuss 'sam validate' seems to still be broken if using Fn::Transform and AWS::Include to reference and include an OpenAPI definition in a separate file while having a Globals -> Api -> Cors config in the SAM template.
SAM template:
If I comment out my global cors config in my SAM template then validation works fine.
afittz commentedon Apr 4, 2020
@jfuss I'm also experiencing the same issue paulsson-cs is reporting. Anyway we can get this one reopened to address this?
Qamar-Zaman commentedon Apr 20, 2020
You need to add
swagger: 2.0underDefinitionBodyfor your APIpiersf commentedon Apr 27, 2020
This still seems to be an issue: #1074 (comment)
2 remaining items
julianste commentedon Mar 30, 2021
Same issue here, this is my current workaround:
rainabba commentedon Mar 31, 2021
@julianste I've moved to SAM nightlies (1.21.1) to see if it was resolved there. I tried your 3 workaround lines, but got another error. Seems it's not happy with that incomplete definition.
julianste commentedon Apr 2, 2021
@rainabba my workaround probably just works for
AWS::Serverless::HttpApi. Maybe insert some dummy dict containingoptions?EDIT: Something like this seems to satisfy
sam validatebut I'm not sure about any other implications...NickHeap2 commentedon Oct 29, 2021
@julianste @rainabba I have this working locally. The fix is to get the validator to detect the Transform->Include->Location pattern and replace the DefinitionBody with the contents of the yaml file itself during validation.
TodorGinchev commentedon May 16, 2022
The workaround of copying contents of the api definition swagger file and pasting them exactly as they are under "DefinitionBody:" works. Thank you!
However, this is not a practical solution and a very error-prone one. @jfuss I do not think this ticket should be kept closed, the issue is still there.
aleguern commentedon May 16, 2022
It worked without the definitionBody for couple of AWS SAM versions, and now it does not, possible regression ?
NickHeap2 commentedon May 16, 2022
@aleguern I fixed this problem under #3451 but it had to be rolled back due to this issue #3676
NickHeap2 commentedon May 16, 2022
@aleguern Turns out the fix for this was easy enough so I'm pushing this through again in a new PR.
aleguern commentedon May 16, 2022
Great news thank you so much
NickHeap2 commentedon May 16, 2022
@aleguern PR is here: #3882
Workaround for sam validate
cortexcompiler commentedon Jan 18, 2023
I see this same issue in SAM CLI version 1.61.0, it looks like the PR #3882 was never merged. Are there any plans to fix this?
NickHeap2 commentedon Jan 18, 2023
@cortexcompiler I ran out of capacity to make all the required changes that came up in the fix PR.
If this is important to you I can try and revive the PR when I have time.
ansiichan commentedon Apr 21, 2023
problem still persists on version 1.81.0
error message
Error: [InvalidResourceException('Api', "Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition.")] ('Api', "Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition.")is still beeing displayed erroneously even after passing correctly
stack still deploys and builds fine
workaround is still just to pass contents of .yaml file int the definition body directly
evin-murphy commentedon Oct 4, 2023
I am getting this error
"Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition"when using Fn::Transform on my OAS3 file and defining an IP whitelist; looks to be related to this issue and #3041. The deploy is successful if I skipsam validate.with
I can use the workaround provided in #803 (comment) it would be great if this could be fixed.
@NickHeap2 do you think you would have capacity sometime to re-open your previous PR #3882? No worries if not.