首页 文章

使用swashbuckle的AWS API Gateway Swagger

提问于
浏览
2

我想使用Swashbuckle.AspNetCore从ASP.NET Core Web API生成AWS API Gateway swagger(http://docs.aws.amazon.com/apigateway/latest/developerguide/api-as-lambda-proxy-export-swagger-with-extensions.html) .

如果有人有解决方案,请告诉我 .

注意:我遇到了这个How to generate Options(CORS) with Swagger . 并希望做同样的事情 . 你能指导我吗?

谢谢,阿比达利

1 回答

  • 1

    AWS Api网关在swagger中使用x-amazon-apigateway- *扩展来配置REST Api .

    我不认为已经有一个库会通过Swashbuckle为您管理它,但Swashbuckle有一些接口可以实现生成自定义swagger扩展,如Swashbuckle documentation中所述 . 例如,如果要生成x-amazon-apigateway-integration扩展,可以通过实现 Swashbuckle.AspNetCore.SwaggerGen.IOperationFilter 接口来实现:

    public class AwsApiGatewayIntegrationFilter : IOperationFilter
        {
            public void Apply(Operation operation, OperationFilterContext context)
            {
                operation.Extensions.Add("x-amazon-apigateway-integration",new
                {
                    type = "aws",
                    uri = "arn_to_your_aws_resource"
                });
            }
        }
    

    并在swagger发电机设置期间配置它:

    services.AddSwaggerGen(c =>
    {
         c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "My API",
                    Description = "",
                    TermsOfService = "",
                });
        c.OperationFilter<AwsApiGatewayIntegrationFilter>();
    });
    

相关问题