Fixed apiexplorer
This commit is contained in:
@@ -17,7 +17,12 @@ Need to consider re-thinking versioning system of api to remove the complexity o
|
||||
Test out versioning in the test project I made following the Swashbuckle guide for multiple docs:
|
||||
https://github.com/domaindrivendev/Swashbuckle.AspNetCore#list-multiple-swagger-documents
|
||||
|
||||
Because maybe this is the way to go?
|
||||
|
||||
- Update my code to the modern standard: https://kimsereyblog.blogspot.com/2018/08/apicontroller-attribute-in-asp-net-core.html
|
||||
- Note that that above is for v2.2 my controllers appear to date from the v1 .net core era and I will need to then move them to the .netcore 3.1 era changes
|
||||
- This is important and worth doing to make sure everything will work going forward (the swashbuckle [apicontroller] attribute debacle is proof of this)
|
||||
|
||||
|
||||
|
||||
|
||||
Need a sprint to get to a fully testable client with entry form, list and as much as possible all features from COMMON-* specs list
|
||||
|
||||
@@ -28,9 +28,9 @@ The "response body" section will contain the return value, something similar to
|
||||
|
||||
The highlighted line above contains the token you require, copy the token value not including the quotation marks. This is your access token.
|
||||
|
||||
Click on the "Authorize" button at the top of the API console and a popup dialog box will open. In the "Value" box the dialog enter the word Bearer followed by a space and then your api token, for example using the above you would paste in:
|
||||
Click on the "Authorize" button at the top of the API console and a popup dialog box will open. In the "Value" box the dialog enter your api token, for example using the above you would paste in:
|
||||
|
||||
`Bearer xyGhbGciOiJIUzI1NiIsInR4cCI6IkpXVCJ9.utJpYXQ4OiIxNqE4MDM0MzcfIiwiZXhwjjoiMTUyMDYyNjM8MCIsImlocyI0IkF53U5vdmEiLCJpZCI6IjEifQ.z7QaHKt2VbcysunIvsfa-51X7owB1EYcyhpkdkfaqzy`
|
||||
`xyGhbGciOiJIUzI1NiIsInR4cCI6IkpXVCJ9.utJpYXQ4OiIxNqE4MDM0MzcfIiwiZXhwjjoiMTUyMDYyNjM8MCIsImlocyI0IkF53U5vdmEiLCJpZCI6IjEifQ.z7QaHKt2VbcysunIvsfa-51X7owB1EYcyhpkdkfaqzy`
|
||||
|
||||
then click on the "Authorize" button inside the popup dialog box.
|
||||
|
||||
|
||||
@@ -32,11 +32,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Attachment controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class AttachmentController : Controller
|
||||
public class AttachmentController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AttachmentController> log;
|
||||
|
||||
@@ -19,10 +19,11 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Authentication controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
public class AuthController : Controller
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AuthController> log;
|
||||
|
||||
@@ -15,11 +15,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Enum pick list controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class AyaEnumPickListController : Controller
|
||||
public class AyaEnumPickListController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AyaTypeController> log;
|
||||
|
||||
@@ -15,11 +15,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// AyaType list controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class AyaTypeController : Controller
|
||||
public class AyaTypeController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AyaTypeController> log;
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Util;
|
||||
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -34,7 +19,7 @@ using System.Linq;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
|
||||
|
||||
|
||||
//FROM DOCS HERE:
|
||||
//https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
|
||||
@@ -46,11 +31,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// and triggering a restore from backup
|
||||
///
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class BackupController : Controller
|
||||
public class BackupController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<BackupController> log;
|
||||
|
||||
@@ -19,11 +19,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class DataFilterController : Controller
|
||||
public class DataFilterController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<DataFilterController> log;
|
||||
|
||||
@@ -19,10 +19,11 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Log files controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
public class EventLogController : Controller
|
||||
public class EventLogController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LogFilesController> log;
|
||||
|
||||
@@ -18,12 +18,13 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class FormCustomController : Controller
|
||||
public class FormCustomController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<FormCustomController> log;
|
||||
|
||||
@@ -28,12 +28,13 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
/// <summary>
|
||||
/// Import AyaNova 7 data controller
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class ImportAyaNova7Controller : Controller
|
||||
public class ImportAyaNova7Controller : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<ImportAyaNova7Controller> log;
|
||||
|
||||
@@ -17,11 +17,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// JobOperations controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class JobOperationsController : Controller
|
||||
public class JobOperationsController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<JobOperationsController> log;
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
/// <summary>
|
||||
/// License route
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class LicenseController : Controller
|
||||
public class LicenseController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LicenseController> log;
|
||||
|
||||
@@ -23,11 +23,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Localized text controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class LocaleController : Controller
|
||||
public class LocaleController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LocaleController> log;
|
||||
|
||||
@@ -16,11 +16,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Log files controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
//[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class LogFilesController : Controller
|
||||
public class LogFilesController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LogFilesController> log;
|
||||
|
||||
@@ -18,10 +18,11 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Log files controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Authorize]
|
||||
public class MetricsController : Controller
|
||||
public class MetricsController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LogFilesController> log;
|
||||
|
||||
@@ -19,11 +19,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Search
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class SearchController : Controller
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<WidgetController> log;
|
||||
|
||||
@@ -15,10 +15,11 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Server state controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
public class ServerStateController : Controller
|
||||
public class ServerStateController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<ServerStateController> log;
|
||||
|
||||
@@ -15,11 +15,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Enum pick list controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class TagListController : Controller
|
||||
public class TagListController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<AyaTypeController> log;
|
||||
|
||||
@@ -13,11 +13,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
///Test controller class used during development
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class TrialController : Controller
|
||||
public class TrialController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<WidgetController> log;
|
||||
|
||||
@@ -19,11 +19,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// User
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class UserController : Controller
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<UserController> log;
|
||||
|
||||
@@ -19,11 +19,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// UserOptions
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class UserOptionsController : Controller
|
||||
public class UserOptionsController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<UserOptionsController> log;
|
||||
|
||||
@@ -22,11 +22,12 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// Sample controller class used during development for testing purposes
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class WidgetController : Controller
|
||||
public class WidgetController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<WidgetController> log;
|
||||
|
||||
@@ -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";
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user