我想使用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。并希望做同样的事情。你能指导我吗?
谢谢, Abidali
答案 0 :(得分:2)
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>();
});
答案 1 :(得分:0)
asidis答案的最新版本如下:(使用dotnet 3.0.0和swashbuckle 5.0.0-rc4)
public class AwsApiGatewayIntegrationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
operation.Extensions.Add("x-amazon-apigateway-integration", new OpenApiObject
{
["type"] = new OpenApiString("aws"),
["uri"] = new OpenApiString("arn_to_your_aws_resource"),
});
}
}
在Startup.cs
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
c.OperationFilter<AwsApiGatewayIntegrationFilter>();
);