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

0.2.5 & 0.2.6 Cannot parse Swagger definition #275

Closed
Tanbouz opened this issue Jan 24, 2018 · 14 comments
Closed

0.2.5 & 0.2.6 Cannot parse Swagger definition #275

Tanbouz opened this issue Jan 24, 2018 · 14 comments

Comments

@Tanbouz
Copy link

Tanbouz commented Jan 24, 2018

  • 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?

@majway27
Copy link

@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
....

@pal-philbasford
Copy link

It is external YAML that does not work. External JSON works fine.

@pal-philbasford
Copy link

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.

@rbbhar
Copy link

rbbhar commented Jan 29, 2018

@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.

@ldm314
Copy link

ldm314 commented Jan 30, 2018

Ran into this today as well, switching to json fixed it.

@ldm314
Copy link

ldm314 commented Jan 30, 2018

The bug is here:

https://github.com/awslabs/aws-sam-local/blob/dbbd5948fef0b51d412b4e2631e004c7b113c35f/router/api.go#L35-L42

Line 42 assumes that the file loaded is a JSON file.

@ldm314
Copy link

ldm314 commented Jan 30, 2018

If the file location is a string, in my case it was 'api.yml', then the first case is met:

https://github.com/awslabs/aws-sam-local/blob/dbbd5948fef0b51d412b4e2631e004c7b113c35f/router/api.go#L158-L163

The URI method only reads the file, regardless of contents:

https://github.com/awslabs/aws-sam-local/blob/dbbd5948fef0b51d412b4e2631e004c7b113c35f/router/api.go#L191-L197

The YAML file text is being saved in the variable 'jsonDefinition', failing at line 42 when it tries to parse the YAML as JSON.

@aaronj314
Copy link

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

@ldm314
Copy link

ldm314 commented Jan 31, 2018

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.

@jhovell
Copy link

jhovell commented Feb 2, 2018

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

@wolfeidau
Copy link

I got this error as well, removing swagger: 2.0 from the inline yaml resolved it.

@metaskills
Copy link
Contributor

I also found that quoting works fine. So swagger: "2.0" worked.

@michaelj-smith
Copy link

I've had the same experience. Simple workaround, but odd.

@sanathkr
Copy link
Contributor

sanathkr commented Jun 1, 2018

this is fixed as of v0.3.0

@sanathkr sanathkr closed this as completed Jun 1, 2018
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

No branches or pull requests