Adding endpoint descriptions in swagger for services from separate modules
- ABP Framework version. 5.0.1
I am trying to create a better documentation for my API by adding a ///summary for every public method. I want it to be visible in my swagger. I already know that I cannot add summary in AppServices, I have to create Controllers and add summaries there. I also configured the project following this document. What should I do to see summaries of methods defined in separate modules? When I added Controllers in .HttpApi projects their descriptions were not visible in swagger. Is this even possible to achieve that?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
bump? am also interested in enabling SwaggerUI description from xmldoc comments
there seems to be no extension point to enable xmldocs as described in the Microsoft docs...
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
....
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Blox API");
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
options.DocExpansion(DocExpansion.None);
});
....
}
Never mind, I've found that SwaggerGen is already setup in the ...HttpApiHostModule.ConfigureSwagger method..
Still, I've tried adding the xml doc files, as described below
private static void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"Project", "Project API"}
},
options =>
{
//options.SwaggerDoc("v1", new OpenApiInfo {Title = "Project API", Version = "v1"});
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
options.SwaggerDoc("v1", new OpenApiInfo {
Title = "Project API",
Version = "v1",
TermsOfService = null,
Description = null,
License = new OpenApiLicense { Name = "Proprietary" }
});
IncludeXmlDocFiles(options, $"Project.Namespace.*.xml");
});
}
private static void IncludeXmlDocFiles(SwaggerGenOptions options, string pattern)
{
string WildcardToRegex(string wildcardPattern)
{
return $"^{Regex.Escape(wildcardPattern).Replace("\\*", ".*").Replace("\\?", ".")}$";
}
//Find XML Comments File In Pattern
var basePath = AppContext.BaseDirectory;
var regex = new Regex(WildcardToRegex(pattern));
var allDirectoryFiles = Directory.GetFiles(basePath, "*.*", SearchOption.TopDirectoryOnly).ToList();
var xmlDocFiles = allDirectoryFiles.Where(p => regex.IsMatch(Path.GetFileName(p))).ToList();
foreach (var xmlDocFilePath in xmlDocFiles)
{
options.IncludeXmlComments(xmlDocFilePath, true);
}
}
Xml files are generated, found and included via IncludeXmlComments, but still, APIService Actions that do have comments (visible in the xml files also) DO NOT show up on the Swagger UI...
What am I missing?
@maliming any ideas ?
but still, APIService Actions that do have comments (visible in the xml files also) DO NOT show up on the Swagger UI...
Can you share a simple project?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.