1

我在 .Net 微服务网关中使用 Swagger for Ocelot。我正在为 ocelot swagger 使用以下包:

安装包 MMLib.SwaggerForOcelot -版本 1.10.1

我收到以下问题。

在此处输入图像描述

正如我在图片中提到的,http 正在网关请求 URL 中复制

我的项目配置如下,

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <UserSecretsId>38efa0b7-845b-41f3-914c-1bfc80defa9b</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>..\..\..\..</DockerfileContext>
    <DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
    <PackageReference Include="MMLib.SwaggerForOcelot" Version="1.10.0" />
    <PackageReference Include="Ocelot" Version="13.8.0" />
  </ItemGroup>

</Project>

我的 Ocelot 配置如下,

{
  "ReRoutes": [   
    {
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "customer.api",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/Customer/{everything}",
      "UpstreamHttpMethod": [ "POST", "PUT", "GET", "DELETE", "PATCH" ],
      "SwaggerKey": "skCustomer"
    }
  ],
  "SwaggerEndPoints": [   
    {
      "Key": "skCustomer",
      "Config": [
        {
          "Name": "Customer API",
          "Version": "v1",
          "Url": "http://customer.api:80/CustomerAPI/Customer/swagger.json"
        }
      ]
    }
  ],
  "GlobalConfiguration": {
    "RequestIdKey": "OcRequestId",
    "AdministrationPath": "/administration"
  }
}

我在启动文件中的招摇配置如下,

public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerForOcelot(_cfg);
            services.AddOcelot(_cfg);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseSwaggerForOcelotUI(_cfg, opt =>
            {
                opt.EndPointBasePath = "/swagger/docs";
            });

            await app.UseOcelot();
        }
4

1 回答 1

2

看起来像问题该方案是重复的

不幸的是,它仍然没有修复。

作为一种解决方法,您可以降级到1.8版

于 2020-01-17T06:49:14.460 回答