2016-03-21 16 views
1

これは、私は現在、私の闊歩ファイル内に持っているものです。API Gatewayを介してパス変数を渡す方法

"/v1/user/{username}": { 
     "get": { 
     "consumes": ["application/json"], 
     "produces": ["application/json"], 
     "parameters": [{ 
      "name": "username", 
      "in": "path", 
      "description": "Username of user", 
      "required": true, 
      "type": "string" 
     }], 
     "responses": { 
      "200": { 
      "description": "user retrieved", 
      "schema": { 
       "type": "array", 
       "items": { 
       "$ref": "#/definitions/User" 
       } 
      } 
      } 
     }, 
     "x-amazon-apigateway-integration": { 
      "type": "http", 
      "uri": "http://useroregon.recopspipeline.com/v1/user/{username}", 
      "httpMethod": "GET", 
      "responses": { 
      "default": { 
       "statusCode": "200", 
       "responseTemplates": { 
       "application/json": "$input.json('$.body')" 
       } 
      } 
      } 
     } 
     }, 

しかし、私のバックエンドは、単にパス変数として「{ユーザー名}」を受信します。
誰もパス変数を送信する方法を知っていますか?
swagger jsonファイルやGUIを使って行う方法に関するヒントは素晴らしいでしょう!

答えて

1

このOpenAPI(fag。Swagger)ファイルは、リクエストパラメータとプロキシされたサービス(requestParameters in x-amazon-apigateway-integration)の間のマッピングを欠いています。あなたは、この取得API Gatewayコンソールを使用して、それをエクスポートするプロキシ操作であなたのAPIを設計する場合

"x-amazon-apigateway-integration": { 
     "type": "http", 
     "uri": "http://useroregon.recopspipeline.com/v1/user/{username}", 
     "requestParameters": { 
     "integration.request.path.username": "method.request.path.username" 
     } 
     "httpMethod": "GET", 
     "responses": { 
     "default": { 
      "statusCode": "200", 
      "responseTemplates": { 
      "application/json": "$input.json('$.body')" 
      } 
     } 
     } 
    } 

swagger: "2.0" 
info: 
    title: "Proxy" 

schemes: 
- "https" 

paths: 
    /test/{username}: 
    get: 
     produces: 
     - "application/json" 
     parameters: 
     - name: "username" 
     in: "path" 
     required: true 
     type: "string" 
     responses: 
     200: 
      description: "200 response" 
      schema: 
      $ref: "#/definitions/Empty" 
     x-amazon-apigateway-integration: 
     responses: 
      default: 
      statusCode: "200" 
     requestParameters: 
      integration.request.path.username: "method.request.path.username" 
     passthroughBehavior: "when_no_match" 
     httpMethod: "GET" 
     uri: "http://somedomain.com/{username}" 
     type: "http" 

definitions: 
    Empty: 
    type: "object" 

をあなたの定義もpassthroughBehavior: "when_no_match"を欠いているが、それは問題ではないかもしれません。

関連する問題