上一章快速使用SqlSugar搭建了netcore api项目,我的第一个netcore2.2 api项目搭建(一)

这一章实现目标二:api使用Swagger,实现api文档管理

 效果图:第一张收缩,第二张展开,共有2个控制器:values和Account;控制器有注释,api有注释,实体有注释

我的第一个netcore2.2 api项目搭建(二)我的第一个netcore2.2 api项目搭建(二)

 

1.1添加swagger引用

nuget搜索:Swashbuckle.AspNetCore,安装

我的第一个netcore2.2 api项目搭建(二)

 

1.2在startup中注册swagger

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //添加api管理
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info
                {
                    //Version = "v1",
                    Title = "MyFirst API",//" API",
                    //Description = "",
                    //TermsOfService = "None",
                    //Contact = new Contact
                    //{
                    //    Name = "",
                    //    Email = string.Empty,
                    //    Url = ""
                    //},
                    //License = new License
                    //{
                    //    Name = "Use under LICX",
                    //    Url = ""
                    //}
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                options.IncludeXmlComments(xmlPath, true);
                xmlPath = Path.Combine(AppContext.BaseDirectory, "JH.OPEMR.Model.xml");
                options.IncludeXmlComments(xmlPath, true);
            });
        }
View Code

相关文章:

  • 2021-10-07
  • 2022-12-23
  • 2021-11-02
  • 2021-12-10
  • 2021-06-11
  • 2022-12-23
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-09-17
  • 2021-08-24
相关资源
相似解决方案