【发布时间】:2017-01-31 19:44:04
【问题描述】:
我已经在我的 ASP.NET Core RC1 应用程序中集成了 swagger 以及以下 NuGet 包。
"Swashbuckle.SwaggerGen": "6.0.0-rc1-final",
"Swashbuckle.SwaggerUi": "6.0.0-rc1-final"
这是 swagger 集成的代码。
public void ConfigureServices(IServiceCollection services)
{
....
.....
//*** Configure Swagger Document Information.
services.ConfigureSwaggerDocument(options =>
{
//*** Define incremental API version.
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "TEST APIs",
Description = "Test API Methods",
TermsOfService = "",
});
//*** Assign the API - Swagger helper document.
options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(helperDocPath));
});
//*** Configure the Swagger schema settings.
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(helperDocPath));
});
....
....
}
//**** Configure Method
private void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
....
//*** Add Swagger pluggins to application environment.
app.UseSwaggerGen();
app.UseSwaggerUi();
}
代码生成 swagger 文档,同时使用 localhost -> "http://localhost:8080/testapiproject/swagger/ui/index.html" 在本地访问它。
但是,在部署服务器中部署代码后,我仍然会收到 swagger 文档,但我在底部收到“错误”,点击后显示,
{"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://<applicationdomainname>:8080//testapiproject/swagger/v1/swagger.json"}]}.
【问题讨论】:
-
http://:8080//testapiproject/swagger/v1/swagger.json这条路径似乎是错误的。hostname不见了。您正在尝试从错误的域获取 json。 -
本地主机以外的任何内容,底部显示错误,这是架构验证错误。
标签: c# asp.net-core swagger