|
35 | 35 | using Microsoft.AspNetCore.HttpOverrides;
|
36 | 36 | using Microsoft.Extensions.Options;
|
37 | 37 | using Microsoft.IdentityModel.Logging;
|
| 38 | +using Microsoft.OpenApi.Models; |
38 | 39 | using Serilog;
|
39 | 40 | using Serilog.Enrichers.Sensitive;
|
40 | 41 | using Serilog.Exceptions;
|
@@ -130,6 +131,67 @@ static WebApplication CreateApp(string[] args)
|
130 | 131 |
|
131 | 132 | static void ConfigureServices(IServiceCollection services, IConfiguration configuration, IHostEnvironment environment)
|
132 | 133 | {
|
| 134 | + services.AddEndpointsApiExplorer(); |
| 135 | + |
| 136 | + services.AddSwaggerGen(c => |
| 137 | + { |
| 138 | + c.CustomSchemaIds(t => |
| 139 | + { |
| 140 | + static string GetReadableName(Type type) |
| 141 | + { |
| 142 | + if (!type.IsGenericType) |
| 143 | + { |
| 144 | + return type.Name |
| 145 | + .Replace("DTO", string.Empty) |
| 146 | + .Replace("Command", "Request") |
| 147 | + .Replace("Query", "Request"); |
| 148 | + } |
| 149 | + |
| 150 | + var typeName = type.Name |
| 151 | + .Replace("HttpResponseEnvelopeResult", "ResponseWrapper") |
| 152 | + .Replace("PagedHttpResponseEnvelopeResult", "PagedResponseWrapper"); |
| 153 | + var name = $"{typeName[..typeName.IndexOf('`')]}_{string.Join("_", type.GetGenericArguments().Select(GetReadableName))}"; |
| 154 | + return name; |
| 155 | + } |
| 156 | + |
| 157 | + return GetReadableName(t); |
| 158 | + }); |
| 159 | + |
| 160 | + c.AddServer(new OpenApiServer { Url = "https://nmshd-bkb.demo.meinbildungsraum.de" }); |
| 161 | + c.AddServer(new OpenApiServer { Url = "https://nmshd-bkb.meinbildungsraum.de" }); |
| 162 | + c.AddServer(new OpenApiServer { Url = "https://pilot.enmeshed.eu" }); |
| 163 | + |
| 164 | + c.AddSecurityDefinition( |
| 165 | + "oauth2", |
| 166 | + new OpenApiSecurityScheme |
| 167 | + { |
| 168 | + Type = SecuritySchemeType.OAuth2, |
| 169 | + Flows = new OpenApiOAuthFlows |
| 170 | + { |
| 171 | + Password = new OpenApiOAuthFlow |
| 172 | + { |
| 173 | + TokenUrl = new Uri("/connect/token", UriKind.Relative) |
| 174 | + } |
| 175 | + } |
| 176 | + }); |
| 177 | + |
| 178 | + c.AddSecurityRequirement( |
| 179 | + new OpenApiSecurityRequirement |
| 180 | + { |
| 181 | + { |
| 182 | + new OpenApiSecurityScheme |
| 183 | + { |
| 184 | + Reference = new OpenApiReference |
| 185 | + { |
| 186 | + Id = "oauth2", //The name of the previously defined security scheme. |
| 187 | + Type = ReferenceType.SecurityScheme |
| 188 | + } |
| 189 | + }, |
| 190 | + new List<string>() |
| 191 | + } |
| 192 | + }); |
| 193 | + }); |
| 194 | + |
133 | 195 | services.ConfigureAndValidate<BackboneConfiguration>(configuration.Bind);
|
134 | 196 |
|
135 | 197 | #pragma warning disable ASP0000 // We retrieve the BackboneConfiguration via IOptions here so that it is validated
|
@@ -181,6 +243,9 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config
|
181 | 243 |
|
182 | 244 | static void Configure(WebApplication app)
|
183 | 245 | {
|
| 246 | + app.UseSwagger(); |
| 247 | + app.UseSwaggerUI(); |
| 248 | + |
184 | 249 | app.UseSerilogRequestLogging(opts =>
|
185 | 250 | {
|
186 | 251 | opts.EnrichDiagnosticContext = LogHelper.EnrichFromRequest;
|
|
0 commit comments