Fixed apiexplorer

This commit is contained in:
2019-10-18 19:34:46 +00:00
parent c5bd733302
commit 8fdc54ab6a
24 changed files with 102 additions and 81 deletions

View File

@@ -149,23 +149,30 @@ namespace AyaNova
// Add service and create Policy with options
_log.LogDebug("BOOT: init CORS service");
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
//.AllowCredentials()
);
});
#region Swagger
// services
// .AddApiVersioning(options =>
// {
// options.AssumeDefaultVersionWhenUnspecified = true;
// options.DefaultApiVersion = Microsoft.AspNetCore.Mvc.ApiVersion.Parse("8.0");
// options.ReportApiVersions = true;
// });
// services.AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
services.AddApiVersioning();
services
.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = Microsoft.AspNetCore.Mvc.ApiVersion.Parse("8.0");
options.ReportApiVersions = true;
});
services.AddVersionedApiExplorer(options => options.GroupNameFormat = "'v'VVV");
// services.AddSwaggerGen(
@@ -184,8 +191,32 @@ namespace AyaNova
// return versions.Any(v => $"v{v.ToString()}" == docName);
// });
// });
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
services.AddSwaggerGen();
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
services.AddSwaggerGen(
c=>{
//https://stackoverflow.com/questions/56234504/migrating-to-swashbuckle-aspnetcore-version-5
//First we define the security scheme
c.AddSecurityDefinition("Bearer", //Name the security scheme
new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme.",
Type = SecuritySchemeType.Http, //We set the scheme type to http since we're using bearer authentication
Scheme = "bearer" //The name of the HTTP Authorization scheme to be used in the Authorization header. In this case "bearer".
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement{
{
new OpenApiSecurityScheme{
Reference = new OpenApiReference{
Id = "Bearer", //The name of the previously defined security scheme.
Type = ReferenceType.SecurityScheme
}
},new List<string>()
}
});
}
);
#endregion
@@ -349,30 +380,8 @@ namespace AyaNova
#region SWAGGER
_log.LogDebug("BOOT: pipeline - api explorer");
// Enable middleware to serve generated Swagger as a JSON endpoint.
// app.UseSwagger();
// app.UseSwaggerUI(c =>
// {
// // build a swagger endpoint for each discovered API version
// foreach (var description in provider.ApiVersionDescriptions)
// {
// c.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
// }
// //clean up the swagger explorer UI page and remove the branding
// //via our own css
// //NOTE: this broke when updated to v2.x of swagger and it can be fixed according to docs:
// //https://github.com/domaindrivendev/Swashbuckle.AspNetCore#inject-custom-css
// // c.InjectStylesheet("/api/sw.css");
// c.DefaultModelsExpandDepth(-1);
// c.DocumentTitle = "AyaNova API explorer";
// c.RoutePrefix = "api-docs";
// });
app.UseSwagger();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
app.UseSwaggerUI(
options =>
{
@@ -382,8 +391,9 @@ namespace AyaNova
$"/swagger/{description.GroupName}/swagger.json",
description.GroupName.ToUpperInvariant());
}
options.DefaultModelsExpandDepth(-1);//This is meant to hide the Models section that would appear at the bottom of the swagger ui showing *all* models from the api
options.DocumentTitle = "AyaNova API explorer";
options.RoutePrefix = "api-docs";
options.RoutePrefix = "api-docs";
});