简体   繁体   English

使用带有更改的侦听器路径的httpsys时,未为ASP.Net Core Service Fabric服务使用NSwag生成的招摇

[英]Swagger generated using NSwag not found for ASP.Net Core Service Fabric service when using httpsys with altered listener path

When we used NSwag with default settings for ASP.Net Core Service Fabric service, which had altered HttpSys listener url (added path suffix), the generated swagger.json and UI where not found/accessible. 当我们将NSwag与ASP.Net Core Service Fabric服务的默认设置一起使用时,该服务更改了HttpSys侦听器url(添加了路径后缀),生成的swagger.json和UI找不到/无法访问。

Setting url path for HttpSys Listener: 设置HttpSys侦听器的url路径:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return new ServiceInstanceListener[]
        {
            new ServiceInstanceListener(serviceContext =>
                new HttpSysCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    url += "/service1";
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting HttpSys on {url}");


                    return new WebHostBuilder()
                                .UseHttpSys()
                                .ConfigureServices(
                                    services => services
                                        .AddSingleton<StatelessServiceContext>(serviceContext))
                                .UseContentRoot(Directory.GetCurrentDirectory())
                                .UseStartup<Startup>()
                                .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                                .UseUrls(url)
                                .Build();
                }))
        };
    }

And setting app NSwag for ASP.Net Core service: 并为ASP.Net Core服务设置应用程序NSwag:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        // Register the Swagger services
        services.AddSwagger();
    }

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseMvc();

        // Register the Swagger generator and the Swagger UI middlewares
        app.UseSwaggerUi3WithApiExplorer(settings =>
        {
            settings.GeneratorSettings.DefaultPropertyNameHandling =
                PropertyNameHandling.CamelCase;
        });
    }

We solved this by providing swagger Route and Swagger UI Port within NSwag settings in following way: 我们通过以下方式在NSwag设置中提供了醒目的Route和Swagger UI端口来解决此问题:

app.UseSwaggerUi3WithApiExplorer(settings =>
{
    settings.GeneratorSettings.DefaultPropertyNameHandling =
    PropertyNameHandling.CamelCase;
    settings.SwaggerUiRoute = "/swagger";
    settings.SwaggerRoute = "/api-specification.json";
});

Swagger UI became available on baseurl/service1/swagger and swagger.json file on baseurl/service1/api-specification.json Swagger UI在baseurl / service1 / swagger上可用,而swagger.json文件在baseurl / service1 / api-specification.json上可用

It seems, that in case when we did not change swaggerroute settings, NSwag used some default value and was ignoring the change of url path we have done for HttpSys listener. 看来,如果我们不更改swaggerroute设置,则NSwag使用一些默认值,而忽略了为HttpSys侦听器所做的url路径更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 How to set BaseUrl for Swagger in ASP.NET Core Web API using NSwag.AspNetCore (when hosted behind a reverse proxy) - How to set BaseUrl for Swagger in ASP.NET Core Web API using NSwag.AspNetCore (when hosted behind a reverse proxy) ASP.NET Core(HttpSys)路由在本地工作,但在部署时不工作 - ASP.NET Core (HttpSys) Routing works locally but not when deployed 在ASP.NET Core中使用服务类 - Using a service class with asp.net core Azure Service Fabric中的ASP.NET Core应用程序中的WebpackDevMiddleware - WebpackDevMiddleware in ASP.NET Core app in Azure Service Fabric 如何在Service Fabric ASP.NET Core 2中使用WebListenerCommunicationListener - How to use WebListenerCommunicationListener in Service Fabric ASP.NET Core 2 在 ASP.NET 核心的托管服务中使用范围服务 - Using Scoped services within a hosted service in ASP.NET Core 在 ASP.NET Core Blazor 中使用 MongoDB 作为服务 - Using MongoDB as Service in ASP.NET Core Blazor 使用服务 ASP.NET Core 调用参数化构造函数 - Call Parameterized constructor using Service ASP.NET Core 如何使用通用 asp.net 核心获取服务实例 - How to get Service instance using generic asp.net core 在 Asp.Net Core 应用程序的 Singleton 中使用 Scoped 服务 - Using a Scoped service in a Singleton in an Asp.Net Core app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM