Just updated all the things and had to fix a bunch of stuff to get rid of the compiler errors, haven't run anything yet, just got it to compile at this point.
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
@@ -11,6 +12,9 @@ using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Generator;
|
||||
@@ -24,7 +28,8 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
|
||||
namespace AyaNova
|
||||
@@ -36,7 +41,7 @@ namespace AyaNova
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
public Startup(ILogger<Startup> logger, ILoggerFactory logFactory, Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
|
||||
public Startup(ILogger<Startup> logger, ILoggerFactory logFactory, Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
_log = logger;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
@@ -48,7 +53,7 @@ namespace AyaNova
|
||||
|
||||
private readonly ILogger<Startup> _log;
|
||||
private string _connectionString = "";
|
||||
private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
|
||||
private readonly Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
@@ -57,14 +62,23 @@ namespace AyaNova
|
||||
{
|
||||
_log.LogDebug("BOOT: initializing services...");
|
||||
|
||||
|
||||
|
||||
//Server state service for shutting people out of api
|
||||
_log.LogDebug("BOOT: init ApiServerState service");
|
||||
services.AddSingleton(new AyaNova.Api.ControllerHelpers.ApiServerState());
|
||||
|
||||
//Init mvc
|
||||
_log.LogDebug("BOOT: init MVC Core service");
|
||||
var mvc = services.AddMvcCore();
|
||||
_log.LogDebug("BOOT: add json service");
|
||||
mvc.AddNewtonsoftJson();
|
||||
|
||||
|
||||
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
|
||||
// note: the specified format code will format the version as "'v'major[.minor][-status]"
|
||||
_log.LogDebug("BOOT: init ApiExplorer service");
|
||||
services.AddMvcCore().AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
|
||||
services.AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
|
||||
|
||||
_log.LogDebug("BOOT: ensuring user and backup folders exist and are separate locations...");
|
||||
FileUtil.EnsureUserAndUtilityFoldersExistAndAreNotIdentical(_hostingEnvironment.ContentRootPath);
|
||||
@@ -98,7 +112,7 @@ namespace AyaNova
|
||||
bool LOG_SENSITIVE_DATA = false;
|
||||
|
||||
#if (DEBUG)
|
||||
// LOG_SENSITIVE_DATA = true;
|
||||
// LOG_SENSITIVE_DATA = true;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,7 +124,8 @@ namespace AyaNova
|
||||
)//http://www.npgsql.org/efcore/misc.html?q=execution%20strategy#execution-strategy
|
||||
.ConfigureWarnings(warnings => //https://livebook.manning.com/#!/book/entity-framework-core-in-action/chapter-12/v-10/85
|
||||
warnings.Throw( //Throw an exception on client eval, not necessarily an error but a smell
|
||||
Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.QueryClientEvaluationWarning))
|
||||
// Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.QueryClientEvaluationWarning
|
||||
))
|
||||
.EnableSensitiveDataLogging(LOG_SENSITIVE_DATA)
|
||||
);
|
||||
|
||||
@@ -154,7 +169,9 @@ namespace AyaNova
|
||||
|
||||
}).AddMetrics().AddJsonOptions(options =>
|
||||
{
|
||||
options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
|
||||
//2019-10-15 - removed this due to fuckery after update, is it required??? Not sure at this point
|
||||
//if metrics have wrong dates then it's important I guess
|
||||
//options.JsonSerializerOptions.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
|
||||
});
|
||||
|
||||
|
||||
@@ -179,29 +196,55 @@ namespace AyaNova
|
||||
}
|
||||
|
||||
// add a custom operation filter which sets default values
|
||||
c.OperationFilter<SwaggerDefaultValues>();
|
||||
//Removed because will no longer compile the SwaggerDefaultValues but may be needed, not sure it's all a bit muddled
|
||||
// c.OperationFilter<SwaggerDefaultValues>();
|
||||
|
||||
// integrate xml comments
|
||||
c.IncludeXmlComments(XmlCommentsFilePath);
|
||||
|
||||
|
||||
|
||||
//2019-10-15 - Removed this because apikeyscheme is no longer recognized and it appears it *may* not be necessary... TWT
|
||||
//If I have any issues with bearer tokens in swagger then this is probably necessary but in a new way
|
||||
//this is required to allow authentication when testing secure routes via swagger UI
|
||||
c.AddSecurityDefinition("Bearer", new ApiKeyScheme
|
||||
{
|
||||
Description = "JWT Authorization header using the Bearer scheme. Get your token by logging in via the Auth route then enter it here with the \"Bearer \" prefix. Example: \"Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
In = "header",
|
||||
Type = "apiKey"
|
||||
// c.AddSecurityDefinition("Bearer", new ApiKeyScheme
|
||||
// {
|
||||
// Description = "JWT Authorization header using the Bearer scheme. Get your token by logging in via the Auth route then enter it here with the \"Bearer \" prefix. Example: \"Bearer {token}\"",
|
||||
// Name = "Authorization",
|
||||
// In = "header",
|
||||
// Type = "apiKey"
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
|
||||
c.AddSecurityRequirement(new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>
|
||||
|
||||
|
||||
//Obsolete way
|
||||
// c.AddSecurityRequirement(new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>
|
||||
// {
|
||||
// { "Bearer", new string[] { } }
|
||||
// });
|
||||
|
||||
//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
|
||||
{
|
||||
{ "Bearer", new string[] { } }
|
||||
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>()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -275,7 +318,7 @@ namespace AyaNova
|
||||
////////////////////////////////////////////////////////////
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
//
|
||||
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env,
|
||||
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env,
|
||||
AyContext dbContext, IApiVersionDescriptionProvider provider, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, IServiceProvider serviceProvider)
|
||||
{
|
||||
_log.LogDebug("BOOT: configuring request pipeline...");
|
||||
@@ -478,9 +521,9 @@ namespace AyaNova
|
||||
}
|
||||
}
|
||||
|
||||
static Info CreateInfoForApiVersion(ApiVersionDescription description)
|
||||
static Microsoft.OpenApi.Models.OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
|
||||
{
|
||||
var info = new Info()
|
||||
var info = new Microsoft.OpenApi.Models.OpenApiInfo()
|
||||
{
|
||||
Title = $"AyaNova API {description.ApiVersion}",
|
||||
Version = description.ApiVersion.ToString()
|
||||
|
||||
Reference in New Issue
Block a user