0.2.4 sam local start-api works fine
0.2.5 & 0.2.6
Cannot parse Swagger definition: invalid character '-' in numeric literal
If I remove the --- it will Cannot parse Swagger definition: invalid character 's' looking for beginning of value
Using external swagger file since according to docs in-line is not yet supported.
swagger: 2.0
info:
title: example
version: 0.1.0
paths:
/:
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:<<region>>:<<accountId>>:function:${stageVariables.LambdaFunctionName}/invocations
Anyone else facing the same issue?
@Tanbouz, I landed here via google due to the same issue, using the example from https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/swagger.yaml, same errors on 0.2.6.
A json template might be a workaround. https://github.com/awslabs/aws-sam-local/blob/develop/test/templates/open-api/pet-store-simple.json loaded successfully for me during _sam local start-api_.
simple template.yaml excerpt:
...
Description: foo
Resources:
myAPI:
Type: AWS::Serverless::Api
Properties:
StageName: test
DefinitionUri: ./pet-store-simple.json
....
It is external YAML that does not work. External JSON works fine.
Using yaml2json as global, I was able to use prestart npm to convert it. Then use npm start to run sam local start-api using the json as the ref in template.yaml as a work around. Adding the json file to ignore git list so it not commited.
@majway27 @pal-philbasford - I got the same issue after updating to 0.2.6. As you've suggested, using a json swagger file instead of the yaml solved it for me.
Ran into this today as well, switching to json fixed it.
The bug is here:
Line 42 assumes that the file loaded is a JSON file.
If the file location is a string, in my case it was 'api.yml', then the first case is met:
The URI method only reads the file, regardless of contents:
The YAML file text is being saved in the variable 'jsonDefinition', failing at line 42 when it tries to parse the YAML as JSON.
how are you people dealing with variable in the JSON file? For example:
I have this in my template.yml
Type: AWS::Serverless::Api
Properties:
DefinitionUri: ./user-api.json
StageName: Prod
Variables:
ServerlessExpressLambdaFunctionName: !Ref UserFunctions
uri: arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:860388958568:function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations
when used in the JSON version of the swagger spec? I get this error:
Could not extract Lambda function ARN: Could not find match in
I wrote a node app that generates a template.yml and api.json from ejs templates. All of my lambda functions are in a subfolder. Running the app creates an api for all of them when preparing to do a deployment.
Also broken upgrading from 0.2.4 to 0.2.6.
Is this issue planned to be patched? I didn't realize JSON was the only supported Swagger format.
Error I get is:
Cannot parse Swagger definition: json: cannot unmarshal number into Go struct field SwaggerProps.swagger of type string
I got this error as well, removing swagger: 2.0 from the inline yaml resolved it.
I also found that quoting works fine. So swagger: "2.0" worked.
I've had the same experience. Simple workaround, but odd.
this is fixed as of v0.3.0
Most helpful comment
I also found that quoting works fine. So
swagger: "2.0"worked.