Skip to content

Commit

Permalink
fix: solution wide reformat and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Lesage committed Jan 12, 2024
1 parent b5e2797 commit 93b5edd
Show file tree
Hide file tree
Showing 893 changed files with 4,125 additions and 3,277 deletions.
2 changes: 0 additions & 2 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ open Fake.IO.FileSystemOperators
open Fake.DotNet
open ``Build-generic``

open System
open System.IO


let product = "Basisregisters Vlaanderen"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Configuration;

using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;
using System.Threading.Tasks;

/// <summary>
/// Add headers to the response to prevent any caching.
Expand All @@ -18,9 +18,9 @@ public AddNoCacheHeadersMiddleware(RequestDelegate next)

public Task Invoke(HttpContext context)
{
context.Response.Headers.Add(HeaderNames.CacheControl, "no-store, no-cache, must-revalidate");
context.Response.Headers.Add(HeaderNames.Pragma, "no-cache");
context.Response.Headers.Add(HeaderNames.Expires, "0");
context.Response.Headers.Add(HeaderNames.CacheControl, value: "no-store, no-cache, must-revalidate");
context.Response.Headers.Add(HeaderNames.Pragma, value: "no-cache");
context.Response.Headers.Add(HeaderNames.Expires, value: "0");

return _next(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class AppSettings
{
private string? _baseUrl;

public string BaseUrl
{
get => _baseUrl?.TrimEnd(trimChar: '/') ?? string.Empty;
Expand All @@ -14,7 +15,6 @@ public string BaseUrl
public class ApiDocsSettings
{
public string Title { get; set; } = null!;

public ContactSettings Contact { get; set; } = null!;

public class ContactSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AssociationRegistry.Acm.Api.Infrastructure;

using System.Reflection;
using Be.Vlaanderen.Basisregisters.Api;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
using System.Reflection;

[ApiVersionNeutral]
[Route("")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Extensions;

using System;
using ConfigurationBindings;
using Framework;
using Microsoft.Extensions.Configuration;
using System;

public static class ConfigurationExtensions
{
public static PostgreSqlOptionsSection GetPostgreSqlOptionsSection(this IConfiguration configuration)
{
var postgreSqlOptionsSection = configuration
.GetSection(PostgreSqlOptionsSection.Name)
.Get<PostgreSqlOptionsSection>();
.GetSection(PostgreSqlOptionsSection.Name)
.Get<PostgreSqlOptionsSection>();

postgreSqlOptionsSection.ThrowIfInvalid();

return postgreSqlOptionsSection;
}

private static void ThrowIfInvalid(this PostgreSqlOptionsSection postgreSqlOptions)
{
const string sectionName = nameof(PostgreSqlOptionsSection);

Throw<ArgumentNullException>
.IfNullOrWhiteSpace(postgreSqlOptions.Database, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Database)}");
.IfNullOrWhiteSpace(postgreSqlOptions.Database, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Database)}");

Throw<ArgumentNullException>
.IfNullOrWhiteSpace(postgreSqlOptions.Host, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Host)}");
.IfNullOrWhiteSpace(postgreSqlOptions.Host, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Host)}");

Throw<ArgumentNullException>
.IfNullOrWhiteSpace(postgreSqlOptions.Username, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Username)}");
.IfNullOrWhiteSpace(postgreSqlOptions.Username, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Username)}");

Throw<ArgumentNullException>
.IfNullOrWhiteSpace(postgreSqlOptions.Password, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Password)}");
.IfNullOrWhiteSpace(postgreSqlOptions.Password, $"{sectionName}.{nameof(PostgreSqlOptionsSection.Password)}");
}

public static string GetBaseUrl(this IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ public static class DevelopmentExtensions
public static IApplicationBuilder ConfigureDevelopmentEnvironment(this WebApplication app)
{
if (!app.Environment.IsDevelopment()) return app;

return app
.UseDeveloperExceptionPage()
.UseMigrationsEndPoint()
.UseBrowserLink();
.UseDeveloperExceptionPage()
.UseMigrationsEndPoint()
.UseBrowserLink();
}
}
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Extensions;

using System;
using System.IO;
using System.Reflection;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.AspNetCore.Swagger;
using Be.Vlaanderen.Basisregisters.AspNetCore.Swagger.ReDoc;
using ConfigurationBindings;
using Documentation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.IO;
using System.Reflection;

public static class SwaggerExtensions
{
public static IServiceCollection AddAcmApiSwagger(this IServiceCollection services, AppSettings appSettings)
=> services
.AddSwaggerExamplesFromAssemblies(Assembly.GetExecutingAssembly())
.AddSwaggerGen(
options =>
{
options.AddXmlComments(Assembly.GetExecutingAssembly().GetName().Name!);
options.DescribeAllParametersInCamelCase();
options.SupportNonNullableReferenceTypes();
options.MapType<DateOnly>(
() => new OpenApiSchema
{
Type = "string",
Format = "date",
Pattern = "yyyy-MM-dd",
});
options.CustomSchemaIds(type => type.FullName);
options.SwaggerDoc(
"v1",
new OpenApiInfo
{
Version = "v1",
Title = appSettings.ApiDocs.Title,
Description = "---\n" +
"Voor meer algemene informatie over het gebruik van deze API, raadpleeg onze " +
"<a href=\"https://vlaamseoverheid.atlassian.net/wiki/spaces/AGB/pages/6285361348/API+documentatie\">publieke confluence pagina</a>.",
Contact = new OpenApiContact
{
Name = appSettings.ApiDocs.Contact.Name,
Email = appSettings.ApiDocs.Contact.Email,
Url = new Uri(appSettings.ApiDocs.Contact.Url),
},
});
options.ExampleFilters();

options.SchemaFilter<AutoRestSchemaFilter>();

options.OperationFilter<SwaggerDefaultValues>();

options.OperationFilter<DescriptionOperationFilter>();

options.OperationFilter<AddResponseHeadersFilter>();

options.OperationFilter<TagByApiExplorerSettingsOperationFilter>();

options.OperationFilter<AuthorizationResponseOperationFilter>();

options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
options.OrderActionsBy(SortByTag.Sort);

options.DocInclusionPredicate((_, _) => true);
})
.AddSwaggerGenNewtonsoftSupport();
.AddSwaggerExamplesFromAssemblies(Assembly.GetExecutingAssembly())
.AddSwaggerGen(
options =>
{
options.AddXmlComments(Assembly.GetExecutingAssembly().GetName().Name!);
options.DescribeAllParametersInCamelCase();
options.SupportNonNullableReferenceTypes();

options.MapType<DateOnly>(
() => new OpenApiSchema
{
Type = "string",
Format = "date",
Pattern = "yyyy-MM-dd",
});

options.CustomSchemaIds(type => type.FullName);

options.SwaggerDoc(
name: "v1",
new OpenApiInfo
{
Version = "v1",
Title = appSettings.ApiDocs.Title,
Description = "---\n" +
"Voor meer algemene informatie over het gebruik van deze API, raadpleeg onze " +
"<a href=\"https://vlaamseoverheid.atlassian.net/wiki/spaces/AGB/pages/6285361348/API+documentatie\">publieke confluence pagina</a>.",
Contact = new OpenApiContact
{
Name = appSettings.ApiDocs.Contact.Name,
Email = appSettings.ApiDocs.Contact.Email,
Url = new Uri(appSettings.ApiDocs.Contact.Url),
},
});

options.ExampleFilters();

options.SchemaFilter<AutoRestSchemaFilter>();

options.OperationFilter<SwaggerDefaultValues>();

options.OperationFilter<DescriptionOperationFilter>();

options.OperationFilter<AddResponseHeadersFilter>();

options.OperationFilter<TagByApiExplorerSettingsOperationFilter>();

options.OperationFilter<AuthorizationResponseOperationFilter>();

options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
options.OrderActionsBy(SortByTag.Sort);

options.DocInclusionPredicate((_, _) => true);
})
.AddSwaggerGenNewtonsoftSupport();

public static IApplicationBuilder ConfigureAcmApiSwagger(this IApplicationBuilder app)
=> app.UseSwaggerDocumentation(
new SwaggerDocumentationOptions
{
ApiVersionDescriptionProvider = app.ApplicationServices.GetRequiredService<IApiVersionDescriptionProvider>(),
DocumentTitleFunc = groupName => $"Basisregisters Vlaanderen - Verenigingsregister ACM API {groupName}",
HeadContentFunc = _ => Documentation.Documentation.GetHeadContent(),
HeadContentFunc = _ => Documentation.GetHeadContent(),
FooterVersion = Assembly.GetExecutingAssembly().GetVersionText(),
CSharpClient =
{
Expand Down Expand Up @@ -104,11 +109,12 @@ private static void AddXmlComments(this SwaggerGenOptions swaggerGenOptions, str
continue;

swaggerGenOptions.IncludeXmlComments(possiblePath);

return;
}

throw new ApplicationException(
$"Could not find swagger xml docs. Locations where I searched:\n\t- {string.Join("\n\t-", possiblePaths)}");
$"Could not find swagger xml docs. Locations where I searched:\n\t- {string.Join(separator: "\n\t-", possiblePaths)}");
}

private static string CreateXmlCommentsPath(string directory, string name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Json;

using Newtonsoft.Json;
using System;
using System.Globalization;
using Newtonsoft.Json;

public class DateOnlyJsonConvertor : JsonConverter<DateOnly>
{
Expand All @@ -18,6 +18,11 @@ public override void WriteJson(JsonWriter writer, DateOnly value, JsonSerializer
writer.WriteValue(value.ToString(_format, CultureInfo.InvariantCulture));
}

public override DateOnly ReadJson(JsonReader reader, Type objectType, DateOnly existingValue, bool hasExistingValue, JsonSerializer serializer)
public override DateOnly ReadJson(
JsonReader reader,
Type objectType,
DateOnly existingValue,
bool hasExistingValue,
JsonSerializer serializer)
=> DateOnlyHelpers.TryParse((string)reader.Value!, _format);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Json;

using Be.Vlaanderen.Basisregisters.AggregateSource;
using System;
using System.Runtime.Serialization;
using Be.Vlaanderen.Basisregisters.AggregateSource;

[Serializable]
public class InvalidDateFormat : DomainException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Json;

using Newtonsoft.Json;
using System;
using System.Globalization;
using Newtonsoft.Json;

public class NullableDateOnlyJsonConvertor : JsonConverter<DateOnly?>
{
Expand All @@ -16,9 +16,15 @@ public NullableDateOnlyJsonConvertor(string format)
public override void WriteJson(JsonWriter writer, DateOnly? value, JsonSerializer serializer)
=> writer.WriteValue(value.HasValue ? value.Value.ToString(_format, CultureInfo.InvariantCulture) : string.Empty);

public override DateOnly? ReadJson(JsonReader reader, Type objectType, DateOnly? existingValue, bool hasExistingValue, JsonSerializer serializer)
public override DateOnly? ReadJson(
JsonReader reader,
Type objectType,
DateOnly? existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
var readValue = (string)reader.Value!;

if (string.IsNullOrEmpty(readValue)) return null;

return DateOnlyHelpers.TryParse(readValue, _format);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AssociationRegistry.Acm.Api.Infrastructure.Json;

using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;

public class ProblemJsonResponseFilter : IOperationFilter
{
Expand All @@ -20,8 +20,9 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
var openApiMediaType = value.Content.First().Value;

value.Content.Clear();

value.Content.Add(
new KeyValuePair<string, OpenApiMediaType>("application/problem+json", openApiMediaType));
new KeyValuePair<string, OpenApiMediaType>(key: "application/problem+json", openApiMediaType));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public AcmInstrumentation()

_verenigingPerInszGauge =
meter.CreateObservableGauge(name: "ar.acm.p.verenigingPerInsz.g", unit: "events",
description: "vereniging per insz projection",
observeValue: () => VerenigingPerInszEventValue);
description: "vereniging per insz projection",
observeValue: () => VerenigingPerInszEventValue);
}

public ActivitySource ActivitySource { get; }
private ObservableGauge<long> _verenigingPerInszGauge;

public long VerenigingPerInszEventValue = 0;

public void Dispose()
Expand Down
Loading

0 comments on commit 93b5edd

Please sign in to comment.