|
1 | 1 | # SwaggerUI configuration |
2 | 2 |
|
3 | 3 |
|
4 | | -## Registering services at Startup |
| 4 | +## Registering services at Startup (with xml documentation) |
5 | 5 |
|
6 | 6 | ```csharp |
7 | 7 | public Startup(IConfiguration configuration) |
8 | 8 | { |
9 | 9 | Configuration = configuration; |
10 | 10 | } |
11 | 11 |
|
| 12 | +public IConfiguration Configuration { get; } |
| 13 | + |
| 14 | +public void ConfigureServices(IServiceCollection services) |
| 15 | +{ |
| 16 | + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; |
| 17 | + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); |
| 18 | + |
| 19 | + services.AddSwaggerGenConfig("My Web Api", "v1", "Add here a description which will be shown in the swagger UI", true, xmlPath); |
| 20 | + //OR services.AddSwaggerGenConfig("My Web Api", "v1", string.Empty, true, xmlPath); |
| 21 | +} |
| 22 | + |
| 23 | +//OMISSIS |
| 24 | +
|
| 25 | +public void Configure(WebApplication app) |
| 26 | +{ |
| 27 | + app.AddUseSwaggerUI("My Web Api v1"); |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +<b>Note:</b> If you want to add xml documentation to web api you need to add TRUE value to GenerateDocumentationFile tag to csproj project file. |
| 32 | + |
| 33 | + |
| 34 | +## Registering services at Startup (without xml documentation) |
| 35 | + |
| 36 | +```csharp |
| 37 | +public Startup(IConfiguration configuration) |
| 38 | +{ |
| 39 | + Configuration = configuration; |
| 40 | +} |
| 41 | + |
| 42 | +public IConfiguration Configuration { get; } |
| 43 | + |
| 44 | +public void ConfigureServices(IServiceCollection services) |
| 45 | +{ |
| 46 | + services.AddSwaggerGenConfig("My Web Api", "v1", "Add here a description which will be shown in the swagger UI"); |
| 47 | + //OR services.AddSwaggerGenConfig("My Web Api", "v1", string.Empty); |
| 48 | +} |
| 49 | + |
12 | 50 | //OMISSIS |
13 | 51 |
|
14 | 52 | public void Configure(WebApplication app) |
|
0 commit comments