在Swagger中为Ocelot请求URL错误,例如http:// http:// [英] Request URL error in Swagger for Ocelot like http://http://

查看:155
本文介绍了在Swagger中为Ocelot请求URL错误,例如http:// http://的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.Net微服务网关中将Swagger用于Ocelot。我正在使用以下软件包进行豹猫招摇:





我在图片中提到的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},
DownScheme: http ,
DownstreamHostAndPorts:[
{
Host: customer.api,
Port:80
}
],
UpstreamPathTemplate: / api / Customer / {everything},
UpstreamHttpMethod:[ POST, PUT, GET, DELETE, PATCH],
SwaggerKey: skCustomer
}
],
SwaggerEndPoints:[[
{
Key: skCustomer,
Config:[
{
Name:客户API,
Version: v1,
Url: http:// customer。 api:80 / CustomerAPI / Customer / swagger.json
}
]
}
],
GlobalConfiguration:{
RequestIdKey: OcRequestId,
AdministrationPath: / ad ministration
}
}

下面是我在启动文件中的详细配置,

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

//运行时调用此方法。使用此方法来配置HTTP请求管道。
公共异步无效Configure(IApplicationBuilder应用程序,IHostingEnvironment env)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// HSTS的默认值为30天。您可能要针对生产方案更改此设置,请参见https://aka.ms/aspnetcore-hsts。
app.UseHsts();
}

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

等待应用程序。UseOcelot();
}


解决方案

看起来像问题该方案已重复



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



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

I'm using Swagger for Ocelot in .Net microservice gateway. I'm using the following package for ocelot swagger:

Install-Package MMLib.SwaggerForOcelot -Version 1.10.1

I'm getting this following issue.

As I mentioned in the image, the http is replicating in the gateway request URL

My project config is following,

<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>

My Ocelot configuration is following,

{
  "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"
  }
}

My swagger config in startup file is following,

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();
        }

解决方案

It looks like issue The scheme is duplicated.

Unfortunately it is still not fixed.

As a workaround you can downgrade to version 1.8

这篇关于在Swagger中为Ocelot请求URL错误,例如http:// http://的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆