1 public void ConfigureServices(IServiceCollection services)
2 {
3 services.AddOcelotJwtAuthorize();
4 //注入Ocelot
5 services.AddOcelot(Configuration);
6 services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
7
8 services.AddSwaggerGen(options =>
9 {
10 options.SwaggerDoc("ApiGateway", new Info { Title = "网关服务", Version = "v1", Contact = new Contact { Email = "285130205@qq.com", Name = "SwaggerOcelot", Url = "http://10.10.10.10" }, Description = "网关平台" });
11 });
12 }
13
14 public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
15 {
16 if (env.IsDevelopment())
17 {
18 app.UseDeveloperExceptionPage();
19 }
20
21 var apis = new Dictionary<string, string>(
22 new KeyValuePair<string, string>[] {
23 KeyValuePair.Create("SwaggerAuthorize", "Authorize"),
24 KeyValuePair.Create("SwaggerAPI01", "API01"),
25 KeyValuePair.Create("SwaggerAPI02", "API02")
26 });
27
28 app.UseMvc()
29 .UseSwagger()
30 .UseSwaggerUI(options =>
31 {
32 apis.Keys.ToList().ForEach(key =>
33 {
34 options.SwaggerEndpoint($"/{key}/swagger.json", $"{apis[key]} -【{key}】");
35 });
36 options.DocumentTitle = "Swagger测试平台";
37 });
38 await app.UseOcelot();
39 }
1 services.AddMvc()
2 .AddXmlSerializerFormatters() //设置支持XML格式输入输出
3 .AddJsonOptions(op => op.SerializerSettings.ContractResolver = new DefaultContractResolver())//大小写不转换
4 .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
1 [HttpGet("{id}")]
2 [ProducesResponseType(typeof(API01Model), 200)]
3 public ActionResult<API01Model> Get(int id)
4 {
5 return new API01Model { ID = 1, IsSure = true, Price = 2.3m, Describe = "test1" };
6 }