-
-
Save justinyoo/a6f584a0a8b3ea256909 to your computer and use it in GitHub Desktop.
ASP.NET Core Tips & Tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
... | |
services.AddSwaggerGen(); | |
services.ConfigureSwaggerDocument( | |
options => | |
{ | |
options.SingleApiVersion(new Info() { Version = "v1", Title = "Swagger UI" }); | |
options.IgnoreObsoleteActions = true; | |
options.OperationFilter(new ApplyXmlActionComments(GetXmlPath(appEnv))); | |
}); | |
services.ConfigureSwaggerSchema( | |
options => | |
{ | |
options.DescribeAllEnumsAsStrings = true; | |
options.IgnoreObsoleteProperties = true; | |
options.CustomSchemaIds(type => type.FriendlyId(true)); | |
options.ModelFilter(new ApplyXmlTypeComments(GetXmlPath(appEnv))); | |
}); | |
... | |
} | |
private static string GetXmlPath(IApplicationEnvironment appEnv) | |
{ | |
var assembly = typeof(Startup).GetTypeInfo().Assembly; | |
var assemblyName = assembly.GetName().Name; | |
var path = $@"{appEnv.ApplicationBasePath}\{assemblyName}.xml"; | |
if (File.Exists(path)) | |
{ | |
return path; | |
} | |
var config = appEnv.Configuration; | |
var runtime = $"{appEnv.RuntimeFramework.Identifier.ToLower()}{appEnv.RuntimeFramework.Version.ToString().Replace(".", string.Empty)}"; | |
path = $@"{appEnv.ApplicationBasePath}\..\..\artifacts\bin\{assemblyName}\{config}\{runtime}\{assemblyName}.xml"; | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment