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 specはpath item object
として$ref
をサポートしていますが、パスアイテムオブジェクトの定義をどこに置くことができないのか分かりません。私はAPI Gateway swaggerのインポートは、他の場所からyaml
ファイルを引っ張るのを制限すると思うが、私は100%確実ではない。
一顧:インポート可能なノードモジュールとして
も。大丈夫です。 – rynop