swagger/reader.py expects inline swagger definition (BodyDefinition) to be a dict, but it is a string.
Description:
Unable to include inline swagger using BodyDefinition: "swagger" because of this error the function (seems to me) expects a dict but is sent a string. The AWS docs say that it should be a string. If the swagger is "remote" then (from reading reader.py) a string or a dict is accepted, but if it's inline it must be a dict.
Steps to reproduce:
Create a template with a stringified JSON swagger and try to deploy it with "sam deploy"
Observed result:
File "/opt/pipx/venvs/aws-sam-cli/lib/python3.6/site-packages/samcli/commands/deploy/auth_utils.py", line 128, in _auth_definition_body_and_uri for _, verb in swagger.get("paths", {}).items(): AttributeError: 'str' object has no attribute 'get'
Expected result:
A sam deployment.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Ubuntu 20.04.1 LTS
sam --version: SAM CLI, version 1.15.0
Add --debug flag to command you are running
Do you have a reproducing template handy for this error?
Have tried with BodyDefinition as well.
Yeah, I think I'm on a path that may work. Will update here.
@larkinrobert do let us know if you were able to solve it, based on any additional information you can give us, we can triage this to ensure this is not a bug.
In the end, I was not able to solve this. To declare my swagger inline I was required to to use bodydefinition, but every iteration/variation that I tried led to an error due to not meeting the library's expectations (described above). The only way I found that allowed to me to use a swagger inline was to use the translated template that results from sam build --but I do not want to use sam build in my process...if sam build could be made to simply render the template that would be great.
We are using our own build system and view sam build as (at best) a duplication of effort. Before we migrated to swagger we were not using sam build (or package) but successfully running our own build and then deploying the templates we wrote via sam deploy. Now, because we want to use an inline swagger definition (not stored in S3) we are forced to run sam build. The only difference I can discern is that the sam-build rendered template is in yaml and the template I'm starting from is in json.
I am currently focused on work arounds and will not be trying to force the python library to accept the inline swagger.
TLDR; I do not see a path for writing a sam template that includes an inline swagger, in json, and deploying that template directly because the swagger reader will not accept it. I am abandoning that path.