amazon web services - How to reuse a string block in swagger -


i writing swagger file aws api gateway. have use block of text integration every single endpoint. how single end-point looking currently

'/products/{productid}':   get:     tags:       - product     summary: detailed information product     consumes:       - application/json     produces:       - application/json     parameters:       - name: productid         in: path         required: true         type: string     responses:       '200':         description: 200 response         schema:           type: array           items:             $ref: '#/definitions/product'       '404':         description: product not found         schema:           type: array           items:             $ref: '#/definitions/product'     x-amazon-apigateway-integration:       requesttemplates:         application/json: >           ##  see           http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html            ##  template pass through parameters including path,           querystring, header, stage variables, , context through           integration endpoint via body/payload            #set($allparams = $input.params())            {            "body-json" : $input.json('$'),            "params" : {            #foreach($type in $allparams.keyset())               #set($params = $allparams.get($type))           "$type" : {               #foreach($paramname in $params.keyset())               "$paramname" : "$util.escapejavascript($params.get($paramname))"                   #if($foreach.hasnext),#end               #end           }               #if($foreach.hasnext),#end           #end            },            "stage-variables" : {            #foreach($key in $stagevariables.keyset())            "$key" : "$util.escapejavascript($stagevariables.get($key))"               #if($foreach.hasnext),#end           #end            },            "context" : {               "account-id" : "$context.identity.accountid",               "api-id" : "$context.apiid",               "api-key" : "$context.identity.apikey",               "authorizer-principal-id" : "$context.authorizer.principalid",               "caller" : "$context.identity.caller",               "cognito-authentication-provider" : "$context.identity.cognitoauthenticationprovider",               "cognito-authentication-type" : "$context.identity.cognitoauthenticationtype",               "cognito-identity-id" : "$context.identity.cognitoidentityid",               "cognito-identity-pool-id" : "$context.identity.cognitoidentitypoolid",               "http-method" : "$context.httpmethod",               "stage" : "$context.stage",               "source-ip" : "$context.identity.sourceip",               "user" : "$context.identity.user",               "user-agent" : "$context.identity.useragent",               "user-arn" : "$context.identity.userarn",               "request-id" : "$context.requestid",               "resource-id" : "$context.resourceid",               "resource-path" : "$context.resourcepath"               }           }       uri: >-         arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:87126xxxxxxx:function:lambdatest_v3/invocations       passthroughbehavior: never       responses:         default:           statuscode: '200'       httpmethod: post       type: aws 

the part x-amazon-apigateway-integration needs repeated every path. how can not write every-time. possible have string definition @ least hold part application/json?

i tried creating string definition didn't worked on aws import:

definitions:   myapi:     type: string     default: >         #magic          #set($allparams = $input.params())          {          "body-json" : $input.json('$'),          "params" : {          #foreach($type in $allparams.keyset())             #set($params = $allparams.get($type))         "$type" : {             #foreach($paramname in $params.keyset())             "$paramname" : "$util.escapejavascript($params.get($paramname))"                 #if($foreach.hasnext),#end             #end         }             #if($foreach.hasnext),#end         #end          },          "stage-variables" : {          #foreach($key in $stagevariables.keyset())          "$key" : "$util.escapejavascript($stagevariables.get($key))"             #if($foreach.hasnext),#end         #end          },          "context" : {             "account-id" : "$context.identity.accountid",             "api-id" : "$context.apiid",             "api-key" : "$context.identity.apikey",             "authorizer-principal-id" : "$context.authorizer.principalid",             "caller" : "$context.identity.caller",             "cognito-authentication-provider" : "$context.identity.cognitoauthenticationprovider",             "cognito-authentication-type" : "$context.identity.cognitoauthenticationtype",             "cognito-identity-id" : "$context.identity.cognitoidentityid",             "cognito-identity-pool-id" : "$context.identity.cognitoidentitypoolid",             "http-method" : "$context.httpmethod",             "stage" : "$context.stage",             "source-ip" : "$context.identity.sourceip",             "user" : "$context.identity.user",             "user-agent" : "$context.identity.useragent",             "user-arn" : "$context.identity.userarn",             "request-id" : "$context.requestid",             "resource-id" : "$context.resourceid",             "resource-path" : "$context.resourcepath"             }         } 

and in path:

  x-amazon-apigateway-integration:     requesttemplates:       application/json:          $ref: '#/definitions/myapi'     uri: >-       arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:8712xxxxxxxx:function:lambdatest_v3/invocations     passthroughbehavior: never     responses:       default:         statuscode: '200'     httpmethod: post     type: aws 

http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html

if you’re writing swagger api spec , it’s becoming large, can split multiple files. swagger supports json reference (draft) using remote , local pieces of json build swagger document.

json reference overview

json reference uses special key $ref define “reference” piece of json. example following json has reference http://example.com/foo.json:


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -