- Hands-On Serverless Applications with Kotlin
- Hardik Trivedi Ameya Kulkarni
- 259字
- 2025-02-26 15:24:31
Swagger 2.0 JSON documentation with API Gateway extensions
After deploying the API on a stage, there is the option to export the documentation from the console.
The following code block shows the documentation of the Greeter API. We will use this as a boilerplate to create the LetsPoll APIs in Chapter 4, Developing Your Serverless Application:
{
"swagger": "2.0",
"info": {
"version": "2018-07-29T11:09:39Z",
"title": "Greeter API"
},
"schemes": [
"https"
],
"paths": {
"/greeter": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "GreetingInput",
"required": true,
"schema": {
"$ref": "#/definitions/GreetingInput"
}
}
],
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/GreetingResponse"
}
},
"400": {
"description": "400 response",
"schema": {
"$ref": "#/definitions/Error"
}
}
},
"security": [
{
"Greeter-Authorizer": []
},
{
"api_key": []
}
],
"x-amazon-apigateway-request-validator": "Validate body",
"x-amazon-apigateway-integration": {
"uri": "arn:aws:apigateway:us-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-1:162507129690:function:Greeter/invocations",
"responses": {
"default": {
"statusCode": "200"
},
".*Exception*": {
"statusCode": "400"
}
},
"passthroughBehavior": "when_no_templates",
"httpMethod": "POST",
"contentHandling": "CONVERT_TO_TEXT",
"type": "aws"
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
},
"Greeter-Authorizer": {
"type": "apiKey",
"name": "x-authz-key",
"in": "header",
"x-amazon-apigateway-authtype": "custom",
"x-amazon-apigateway-authorizer": {
"authorizerUri": "arn:aws:apigateway:us-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-1:162507129690:function:GreeterAuthorizer/invocations",
"authorizerResultTtlInSeconds": 300,
"type": "token"
}
}
},
"definitions": {
"Error": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"title": "Error Schema"
},
"GreetingResponse": {
"type": "string"
},
"GreetingInput": {
"type": "string"
}
},
"x-amazon-apigateway-request-validators": {
"Validate body": {
"validateRequestParameters": false,
"validateRequestBody": true
}
}
}
The fragments that are API Gateway extensions to Swagger are as follows:
- x-amazon-apigateway-request-validator
- x-amazon-apigateway-integration
- x-amazon-apigateway-request-validators
- securityDefintions