OPTIONS请求的swagger path $ ref

时间:2016-10-26 18:41:17

标签: swagger aws-api-gateway swagger-2.0

我想从swagger.yml文件构建API网关部署。我需要为所有端点支持CORS。我的所有select jt.id as jt_id, (kv.value -> 'value')::text::int as entity_id from json_table jt, jsonb_each(jt.values) kv where kv.value @> '{"Type":"foreign-key"}' 路径定义都完全相同。如何在一个地方定义options路径并在我想要使用的地方options定义它?

我希望做到这样的事情(注意与$ref处于同一级别的$ref: '#/definitions/CorsOptions'):

get

此yaml未通过swagger validation。我怎样才能完成我正在尝试做的事情,这样我的yaml文件就不会很大,并且使用相同的--- 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" 路径定义来臃肿。

swagger spec支持options作为$ref但是我无法弄清楚我可以在哪里放置路径项对象的定义。我认为API Gateway swagger导入限制从其他地方提取path item object文件,但我不是百分百肯定。

2 个答案:

答案 0 :(得分:1)

我认为这不会起作用。 API网关目前仅支持模型和模式的$ ref,而不支持任意对象。我们有一个积压项目来支持更多地方的$ ref,所以我们最终可能会为此添加支持。

答案 1 :(得分:0)

如果您想在任意位置指定@RequestMapping(value = { "/fileUpload" }, method = RequestMethod.POST) @ResponseBody public Integer uploadFile( HttpServletRequest req, HttpServletResponse res) { try { logger.info("file uploaded"); return 0; } catch (Exception e) { res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return 1; } } 值,可以使用expand-swagger-refs模块。

这会将Swagger架构作为输入,并自动内联所有$ ref值,为您提供适合与API网关一起使用的架构。

它在命令行中可用,支持$refstdin

stdout

还作为可导入的Node模块:

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