1 下游实例配置好swagger
2 在oclect 中怎么swagger 数据源 把oclect 上游的路径地址(UpstreamPathTemplate) 指向下游实例 DownstreamPathTemplate 地址
//*****************************服务器配置swagger******************************** { "Routes": [ { "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量 "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "localhost",
"Port": 5030 //服务端口 } ], "UpstreamPathTemplate": "/T5030/{url}", //网关地址--url变量 "UpstreamHttpMethod": [ "Get", "Post" ] }, { "UpstreamPathTemplate": "/webapi/swagger/v1/swagger.json", "UpstreamHttpMethod": [ "Get" ], "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 8080//服务端口 } ], "DownstreamPathTemplate": "/swagger/v1/swagger.json", "DownstreamScheme": "http" }, { "UpstreamPathTemplate": "/webapiV2/swagger/v2/swagger.json", "UpstreamHttpMethod": [ "Get" ], "DownstreamHostAndPorts": [ { "Host": "localhost",
"Port": 8081//服务端口 } ], "DownstreamPathTemplate": "/swagger/v1/swagger.json", "DownstreamScheme": "http" } ] }
3 程序配置swaggerEndpoint
builder.Services.AddSwaggerGen(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI( c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ocelot V1"); c.SwaggerEndpoint("/webapi/swagger/v1/swagger.json", "WebAPI V1"); c.SwaggerEndpoint("/webapiV2/swagger/v2/swagger.json", "WebAPI V2"); }); }
另外 //swagger没有出来的原因是docker 是publish,不是IsDevelopment 也是看不到
是不是很简单。