How to specify mapping templates in AWS SAM - aws-lambda

I have an AWS lambda that acts on an events of the form:
{"id": "some-id", "stuff": "bla-bla-stuff-here" }
Now I want to attach an API Gateway endpoint with POSTs to an url of the form /stuff/{id} where the actual stuff would go in the body. So, on the integration request of the method there is a mapping template section which seems to allow for something like:
{
"id": $input.params('id'),
"stuff": $input.body
}
Now, how do I specify this template in the SAM file?

SAM uses the Proxy integration to Lambda which I don't think works with request/response mapping. If it does, you would need to specify this in Swagger as the DefinitionBody property of the Serverless::Api as SAM doesn't currently have a property for adding Request/Response mapping and generating the Swagger for you. The easiest way to use Swagger is to inspect the generated CloudFormation template of your stack; copy-paste it into your SAM template under DefinitionBody; and then apply the necessary Swagger additions.

Related

How to map path elements to method parameter in spring cloud function web

I'm working on a Microservice that receives webhooks, the idea is to use path variables for some processing down stream,
/webhooks/{foo}/{bar}/{baz}
for example
/webhooks/sony/pony/tony would populate foo=sony; bar=pony; baz=tony.
Can't figure how to make it work in spring cloud function web.
This was never the purpose of spring-cloud-function to replace spring-mvc etc.
Also, Function has only one argument, so what you can do is have Function<Message, ...> and we translate HTTP request into Message where body will turn into payload and HTTP headers will turn into Message headers.

How to expose yaml endpoint in NSwag?

I need to expose the schema definition of API (.net core 2.2) in Yaml not JSON. I'm using NSwag. I found package NSwag.Core.Yaml https://www.nuget.org/packages/NSwag.Core.Yaml/
But I have no idea how I should use it. In Shwasbuckle things are pretty straightforward. Everything you have to do is change the extension to yaml, like this:
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.yaml", "My API V1");
});
What should I do using NSwag?
Will be supported in next NSwag version:
https://github.com/RicoSuter/NSwag/issues/2331

how to validate the json request of rest service

I need to write a code in which i need to validate the tag and the value of the tag in java, spring boot project:
Request:
{
"recipientType": "individual",
"templateId": "acb",
"to": "9999999999"
}
if I will remove templateId tag from the request itself.
Code should through error description: template id is missing
How can I implement this validation in java spring boot project
You can make use of Bean Validation support in Spring to validate the contents of request body.
Here is a nice tutorial explain bean validation in detail.
https://reflectoring.io/bean-validation-with-spring-boot/

Spring Boot Actuator Change the format of /health

Recently I update spring-boot-starter-actuator to 2.2.2 and when I consume the /health endpoint i got:
{
"groups": [],
"status": {
"code": "UP",
"description": ""
}
}
instead of:
{
"status": "UP"
}
And i don't have any clue the reason of this. Any idea? Or how I can refomat the output json to the original format? Not overwrite the HealthIndicator, only reformat.
Thanks in advance.
Spring Actuator 2.2 Health Endpoint JSON documentation says:
The /actuator/health endpoint has changed the resulting JSON format by
renaming details to components for the first-level elements. This
helps to differentiate the actual details returned by a
HealthIndicator from the component indicators that make up composite
health.
As a result of the change, the actuator media type has been bumped
from application/vnd.spring-boot.actuator.v2+json to
application/vnd.spring-boot.actuator.v3+json. If you have tools that
need to consume the older format, you can use an HTTP Accept: header
with the V2 media type, application/vnd.spring-boot.actuator.v2+json.
In addition if you want to see all documentation related to health and what is groups ? how to custom the health indicator take a look the
Current Health Information

Add object to output of swashbuckle/swagger JSON

I have a webapi project configured with swagger, and I need every endpoint to have their own ID, for documentation and consumption purposes.
I would like this ID to be exposed through swagger and in the swashbuckle UI.
The best approach I can find is to create an attribute and operation filter, and have swashbuckle add it to the operation.description text, but I'd prefer for it to:
a) be its own JSON object in the generated swagger obj, and
b) have its own section in the UI (not 'hack' it into a h4 in the description)
Does anyone know if this is possible?
thanks

Resources