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

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

问题描述

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

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

我的项目配置如下,

<属性组><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><项目组><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"/></项目组></项目>

我的 Ocelot 配置如下,

<代码>{重新路由":[{"DownstreamPathTemplate": "/{everything}","下游方案": "http",下游主机和端口":[{"Host": "customer.api",端口":80}],"UpstreamPathTemplate": "/api/Customer/{everything}","UpstreamHttpMethod": [ "POST", "PUT", "GET", "DELETE", "PATCH"],"SwaggerKey": "skCustomer"}],SwaggerEndPoints":[{"Key": "skCustomer",配置":[{"名称": "客户 API","版本": "v1","网址": "http://customer.api:80/CustomerAPI/Customer/swagger.json"}]}],全局配置":{"RequestIdKey": "OcRequestId","管理路径": "/管理"}}

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

public void ConfigureServices(IServiceCollection services){services.AddSwaggerForOcelot(_cfg);services.AddOcelot(_cfg);services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);}//这个方法被运行时调用.使用此方法配置 HTTP 请求管道.公共异步无效配置(IApplicationBuilder 应用程序,IHostingEnvironment 环境){如果 (env.IsDevelopment()){app.UseDeveloperExceptionPage();}别的{//默认的 HSTS 值为 30 天.您可能希望针对生产场景更改此设置,请参阅 https://aka.ms/aspnetcore-hsts.app.UseHsts();}app.UseSwaggerForOcelotUI(_cfg, opt =>{opt.EndPointBasePath = "/swagger/docs";});等待 app.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天全站免登陆