原因是你将实体类放到不同的项目中了,如果不指定位置,swagger无法加载注释。
在下面这段代码中,xmlFilename 指向api的xml,xmlModels 指向实体类的xml,这里注意:实体类也要输出xml
builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "API标题", Description = "API描述" }); var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); //增加实体库的引用,否则无法显示实体注释 var xmlModels = $"{Assembly.Load("CatalogService.Domain").GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlModels)); });
标签:xml,实体类,xmlModels,注释,net,swagger,options From: https://www.cnblogs.com/tudou365/p/17100973.html