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

Support request validators and request/response mappings #299

Closed
kadrach opened this issue Feb 9, 2018 · 8 comments
Closed

Support request validators and request/response mappings #299

kadrach opened this issue Feb 9, 2018 · 8 comments
Labels
area/local/start-api sam local start-api command priority/3-long-term stage/pm-review Waiting for review by our Product Manager, please don't work on this yet type/feature Feature request

Comments

@kadrach
Copy link
Member

kadrach commented Feb 9, 2018

It would be great if aws-sam-local could support the request validation features of the APIGateway and request/response mappings with Velocity templates! Alternatively a log message on local calls that these parts of the definition are being ignored :)

@jfuss jfuss added priority/3-long-term type/feature Feature request area/local/start-api sam local start-api command labels Jun 8, 2018
@brunofitas
Copy link

Hi guys. Any progress on this? This is a really important feature.
Thanks

@ejhayes
Copy link

ejhayes commented Oct 31, 2018

@brunofitas @kadrach I have implemented this functionality locally https://github.com/ejhayes/aws-sam-cli.

To use templates, just need to add the velocity template to the x-amazon-apigateway-integration under requestTemplates, for example:

x-amazon-apigateway-integration:
	...
	requestTemplates:
	  application/json: "...VTL TEMPLATE HERE..."
	...

The velocity template mapping and JSONPath looks to be working fine, but java specific string functions like replaceAll will not work. For example $util.escapeJavaScript($input.json('$.errorMessage')) would work, but $util.escapeJavaScript($input.json('$.errorMessage')).replaceAll("\\'","'") would not.

Hoping to have a PR opened in the next couple days.

@brunofitas
Copy link

Thanks Eric!

@heitorlessa
Copy link
Contributor

heitorlessa commented Nov 1, 2018 via email

@hanstf
Copy link

hanstf commented Sep 20, 2019

Hi, will this going to be implemented ?
also @ejhayes, is your pull request only cater the x-amazon-apigateway-integration ?
As my template is came from the CDK and something like this

      Integration:
        ContentHandling: CONVERT_TO_TEXT
        IntegrationHttpMethod: POST
        IntegrationResponses:
          - ResponseParameters:
              method.response.header.Access-Control-Allow-Origin: "'*'"
            ResponseTemplates:
              application/json: "{\"data\": $input.json('$')}"
            StatusCode: "200"
          - ResponseParameters:
              method.response.header.Access-Control-Allow-Origin: "'*'"
            ResponseTemplates:
              application/json: "{\"message\":\"$input.path('$.message')\"}"
            SelectionPattern: .*Exception.*|.*error.*
            StatusCode: "400"
        PassthroughBehavior: WHEN_NO_TEMPLATES
        RequestTemplates:
          image/jpeg: '{"base64Image":"$input.body","token":"$input.header.Authorization"}'

@rv2673
Copy link

rv2673 commented Jul 7, 2020

@jfuss or others? Is this in the aws sam cli roadmap at all? This issue is more then 2 years old, had contributing PR that was rejected, so is it being worked on at all?

@hirosato
Copy link

hirosato commented Oct 5, 2020

@jfuss I would like to restart this PR. I understand the concerns about adding new dependencies.
How about implementing only $input.json('$') and $input.params().path['paramname'], for example, instead? I mean we can choose a few and often used template mappings and implement them without introducing new dependencies. The implementation should look like simple string replacements (e.g. replacing "$input.json('$')" with body).

@jfuss jfuss added the stage/pm-review Waiting for review by our Product Manager, please don't work on this yet label Oct 13, 2020
@praneetap
Copy link
Contributor

Thanks for your interest in this feature request. We are hesitant to merge this today because with the current resources we would not be able to commit to maintaining this feature in the long run - maintain feature parity and fix issues with the implementation in a timely manner. Given the reaction we can see that this is important to the community and we recommend one of the two alternatives -

  1. We highly recommend you to use SAM Accelerate to test this in your development environment in the cloud. Here is a helpful video to learn more about it, and here is the installation instructions for the beta version. Please let us know if this helps with your testing needs.
  2. If testing in the cloud is not an option for you, we are considering adding plugin support if there is enough interest. Upvote and comment on this tracking issue, if building this as a plugin would be something you would be interested in instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/start-api sam local start-api command priority/3-long-term stage/pm-review Waiting for review by our Product Manager, please don't work on this yet type/feature Feature request
Projects
None yet
Development

No branches or pull requests

10 participants