2016-07-06 3 views
0

AWS API 게이트웨이 용 swagger 파일을 쓰고 있습니다. 모든 단일 끝점에 대해 통합을 위해 텍스트 블록을 사용해야합니다. 단일 엔드 포인트는 모든 경로를 그대로 반복 할 필요가 현재swagger에서 문자열 블록을 재사용하는 방법

'/products/{productId}': 
    get: 
    tags: 
     - product 
    summary: Get detailed information about a 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 

      ## This template will pass through all parameters including path, 
      querystring, header, stage variables, and context through to the 
      integration endpoint via the 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 

X-아마존 - apigateway - 통합에 대한 부분을 찾는 방법이다. 이 아닌 경우을 매번 쓰십시오. 최소한 application/json 부분을 잡고 문자열 정의를 가질 수 있습니까?

나는 문자열 정의를 만들려고하지만 AWS 가져 오기에 근무하지 않았다 : 당신이 만약

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 
+0

이 직접 귀하의 질문에 대답하지 않을 수 있습니다 : 예를 들어 JSON은 http://example.com/foo.json에 대한 참조가 다음? –

+0

예, 그 반대를하려고합니다. 나는 버전 제어 swagger 파일을 가지고 있고'aws apigateway import-rest-api'로 API 게이트웨이에 swagger 파일에 대한 업데이트를 가져 오는 시스템이 있습니다. 게이트웨이 통합은 모든 엔드 포인트에 대해 반복 될 것이므로 같은 블록을 다시 반복하고 싶지는 않습니다. 나는 그것을하는 방법을 알아낼 수 없었다. 이제 배포 프로세스 중에 통합 단락을 추가하려고합니다. – cnvzmxcvmcx

+0

아, 미안, 내가 네가 한 일에 대해 오해했다. import API 메소드를 아직 사용하지 않았으므로 여기서는 도움이되지 않습니다. –

답변

0

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

': 경로에 다음

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" 
      } 
     } 

및 Swagger API 스팩을 쓰고 너무 커지면 여러 파일로 나눌 수 있습니다. Swagger는 원격 및 로컬 JSON을 사용하여 Swagger 문서를 작성하는 JSON 참조 (초안)을 지원합니다.

JSON 참조 개요

JSON 참조 JSON의 조각에 "참조"를 정의하는 특수 키 $ 심판을 사용합니다. 그러나 당신은 당신이 API 게이트웨이 단에서 JSON으로이를 내보낼 수 있음을 인식하고,

관련 문제