2016-10-26 5 views
0

swagger.ymlファイルからAPIゲートウェイのデプロイメントを構築したいとします。すべてのエンドポイントでCORSをサポートする必要があります。すべての私のoptionsパス定義はまったく同じです。どのようにoptionsパスを1つの場所に定義し、$refを使用したいのですか?

--- 
swagger: "2.0" 
info: 
    version: "2016-10-26T03:15:31Z" 
    title: "corstest" 
host: "" 
basePath: "" 
schemes: 
- "https" 
paths: 
    /page: 
    get: 
     produces: 
     - "application/json" 
     responses: 
     200: 
      description: "200 response" 
      schema: 
      $ref: "#/definitions/Empty" 
      headers: 
      Access-Control-Allow-Origin: 
       type: "string" 
     x-amazon-apigateway-integration: 
     responses: 
      default: 
      statusCode: "200" 
      responseParameters: 
       method.response.header.Access-Control-Allow-Origin: "'*'" 
     uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:1234:function:myLambdaFunc/invocations" 
     passthroughBehavior: "when_no_match" 
     httpMethod: "GET" 
     type: "aws_proxy" 
    $ref: '#/definitions/CorsOptions' 
definitions: 
    Empty: 
    type: "object" 
    title: "Empty Schema" 
    CorsOptions: 
    options: 
     consumes: 
     - "application/json" 
     produces: 
     - "application/json" 
     responses: 
     200: 
      description: "200 response" 
      schema: 
      $ref: "#/definitions/Empty" 
      headers: 
      Access-Control-Allow-Origin: 
       type: "string" 
      Access-Control-Allow-Methods: 
       type: "string" 
      Access-Control-Allow-Headers: 
       type: "string" 
      Cache-Control: 
       type: "string" 
     x-amazon-apigateway-integration: 
     responses: 
      default: 
      statusCode: "200" 
      responseParameters: 
       method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" 
       method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" 
       method.response.header.Access-Control-Allow-Origin: "'*'" 
     requestTemplates: 
      application/json: "{\"statusCode\": 200}" 
     passthroughBehavior: "when_no_match" 
     type: "mock" 

このYAMLはswagger validationに合格しない:

私はこのような何かを( getと同じレベルで $ref: '#/definitions/CorsOptions'に注意してください)行うことを期待していました。私は何をやろうとしているのですか?私のyamlファイルは巨大ではなく、同じ optionsパス定義で膨らんでいません。

swagger specpath item objectとして$refをサポートしていますが、パスアイテムオブジェクトの定義をどこに置くことができないのか分かりません。私はAPI Gateway swaggerのインポートは、他の場所からyamlファイルを引っ張るのを制限すると思うが、私は100%確実ではない。

答えて

1

私はそれがうまくいくとは思わない。 API Gatewayは現在、モデルやスキーマに対してのみ$ refをサポートしており、任意のオブジェクトに対してはサポートしていません。より多くの場所で$ refをサポートするためのバックログ項目がありますので、最終的にサポートを追加するかもしれません。

+0

一顧:インポート可能なノードモジュールとして

swagger-expand < my-complex-schema.json > aws-compatible.json 

も。大丈夫です。 – rynop

0

$refの値を任意の場所に指定する場合は、expand-swagger-refsモジュールを使用できます。

これはSwaggerスキーマを入力として受け取り、すべての$ ref値を自動的にインライン化し、APIゲートウェイで使用するのに適したスキーマを返します。

それはstdinstdoutをサポートするコマンドライン上で提供されています:

const { expand, expanded } = require('expand-swagger-refs'); 
const schema = require('./api/swagger.json'); 

// Create a copy of the schema, with $ref values expanded: 
const expandedSchema = expanded(schema); 

// Or expand the schema object in-place (mutates the object): 
expand(schema) 
関連する問題