Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/modules/ROOT/pages/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ the link to the GitHub tag is only added once we are ready to release.
:github-issue: https://github.com/peopleware/net-ppwcode-aspnetcore-host/issues/


:release: 2.0.0
== `{release}`
include::partial$changelog-release-section.adoc[]
include::partial$changelog-{release}.adoc[]

:release: 1.0.0
== `{release}`
include::partial$changelog-release-section.adoc[]
Expand Down
18 changes: 18 additions & 0 deletions docs/modules/ROOT/partials/changelog-2.0.0.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
////
The changelog for a specific release.
Note that it is best to update the changelog as new code is developed.

All attributes used, must be included in this file to keep it self-contained.

This file is translated into markdown and used for the release notes in the GitHub release!
////

=== Changes
* Switch to .NET SDK `10.0.201`
* Upgrade `Swashbuckle.AspNetCore` from `7.3.2` to `10.1.7`
** Fixes link:{github-issue}1[#1] in link:{github-pr}2[#2] by link:{github-user}rvdginste[@rvdginste]


=== Note: breaking change
* Rename `INSSSchemaFilter` to `ForceTypeToStringSchemaFilter`
* Changes to the provided `IOperationFilter` implementations after upgrade to new major version of `Swashbuckle.AspNetCore`
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "disable",
"version": "10.0.102"
"version": "10.0.201"
}
}
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<PackageVersion Include="PPWCode.AspNetCore.Server.I" Version="1.*" />

<!-- Swashbuckle -->
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.*"/>
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="7.*" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="10.*"/>
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="10.*" />

<!-- Asp.Versioning -->
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.*" />
Expand Down
303 changes: 165 additions & 138 deletions src/I.EntityFrameworkCore/packages.lock.json

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions src/I/Swagger/AddDefaultRequiredFields.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -11,14 +11,16 @@

using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Nodes;

using Asp.Versioning;

using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using PPWCode.AspNetCore.Host.I.Bootstrap;
using PPWCode.Vernacular.Contracts.I;
using PPWCode.Vernacular.Exceptions.V;

using Swashbuckle.AspNetCore.SwaggerGen;

Expand All @@ -36,7 +38,7 @@ static AddDefaultRequiredFields()
new(
typeof(ApiVersion),
[
(pd => $"{pd.ParameterDescriptor.Name}", new OpenApiString($"{Startup.DefaultApiVersion.ToString(Startup.ApiVersionFormat)}"))
(pd => $"{pd.ParameterDescriptor.Name}", JsonValue.Create($"{Startup.DefaultApiVersion.ToString(Startup.ApiVersionFormat)}"))
]);
_requiredFieldsWithDefaultValues.Add(defaultRequiredField);
}
Expand All @@ -63,36 +65,49 @@ public override void Apply(OpenApiOperation operation, OperationFilterContext co
continue;
}

foreach ((Func<ApiParameterDescription, string>, IOpenApiAny) tuple in defaultRequiredField.ParamLambdas)
foreach ((Func<ApiParameterDescription, string>, JsonNode) tuple in defaultRequiredField.ParamLambdas)
{
SetParamValue(operation, tuple.Item1.Invoke(parameter), tuple.Item2);
}
}
}

protected void SetParamValue(OpenApiOperation operation, string name, IOpenApiAny defaultValue)
protected void SetParamValue(OpenApiOperation operation, string name, JsonNode defaultValue)
{
OpenApiParameter? param =
Contract.Requires(operation.Parameters is not null);
IOpenApiParameter? parameter =
operation
.Parameters
.SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
if (param is { Required: true })

if (parameter is not null)
{
param.Example = defaultValue;
OpenApiParameter? openApiParameter =
parameter switch
{
OpenApiParameter openApiParameterTemp => openApiParameterTemp,
OpenApiParameterReference openApiParameterReference => openApiParameterReference.RecursiveTarget,
_ => throw new ProgrammingError("Unsupported configuration")
};

if (openApiParameter is not null && openApiParameter.Required)
{
openApiParameter.Example = defaultValue;
}
}
}

public class DefaultRequiredField
{
public DefaultRequiredField(Type type, (Func<ApiParameterDescription, string>, IOpenApiAny)[] paramLambdas)
public DefaultRequiredField(Type type, (Func<ApiParameterDescription, string>, JsonNode)[] paramLambdas)
{
Type = type;
ParamLambdas = paramLambdas;
}

public Type Type { get; }

public (Func<ApiParameterDescription, string>, IOpenApiAny)[] ParamLambdas { get; }
public (Func<ApiParameterDescription, string>, JsonNode)[] ParamLambdas { get; }
}
}
}
4 changes: 2 additions & 2 deletions src/I/Swagger/AddNoContentCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -12,7 +12,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;

using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using Swashbuckle.AspNetCore.SwaggerGen;

Expand Down
4 changes: 2 additions & 2 deletions src/I/Swagger/AddNotFoundResponseCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -16,7 +16,7 @@

using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using Swashbuckle.AspNetCore.SwaggerGen;

Expand Down
8 changes: 4 additions & 4 deletions src/I/Swagger/AddRequestSimulationHeader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -11,7 +11,7 @@

using System.Diagnostics.CodeAnalysis;

using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using PPWCode.AspNetCore.Host.I.Transactional;

Expand All @@ -32,7 +32,7 @@ public override void Apply(OpenApiOperation operation, OperationFilterContext co
{
if (IsPost(context) || IsPut(context) || IsDelete(context))
{
operation.Parameters ??= new List<OpenApiParameter>();
operation.Parameters ??= new List<IOpenApiParameter>();
operation.Parameters.Add(
new OpenApiParameter
{
Expand All @@ -42,7 +42,7 @@ public override void Apply(OpenApiOperation operation, OperationFilterContext co
Schema =
new OpenApiSchema
{
Type = "string"
Type = JsonSchemaType.String
},
Required = false,
});
Expand Down
6 changes: 3 additions & 3 deletions src/I/Swagger/AddSemanticFaultResponseCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -12,7 +12,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;

using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using Swashbuckle.AspNetCore.SwaggerGen;

Expand All @@ -25,7 +25,7 @@ public class AddSemanticFaultResponseCodes : PpwOperationFilter
/// <inheritdoc />
public override void Apply(OpenApiOperation operation, OperationFilterContext context)
{
OpenApiResponse response = new OpenApiResponse { Description = "Parameter validation failed or some business rules were not fulfilled." };
OpenApiResponse response = new() { Description = "Parameter validation failed or some business rules were not fulfilled." };
ConditionalAddResponse(operation, $"{HttpStatusCode.BadRequest:D}", response);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/I/Swagger/AddTransactionalInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -14,7 +14,7 @@
using System.Text;

using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using PPWCode.AspNetCore.Server.I.Transactional;

Expand Down
34 changes: 34 additions & 0 deletions src/I/Swagger/ForceTypeToStringSchemaFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.OpenApi;

using PPWCode.Vernacular.Contracts.I;
using PPWCode.Vernacular.Exceptions.V;

using Swashbuckle.AspNetCore.SwaggerGen;

namespace PPWCode.AspNetCore.Host.I.Swagger;

public class ForceTypeToStringSchemaFilter<T> : ISchemaFilter
where T : class
{
/// <inheritdoc />
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
OpenApiSchema? openApiSchema =
schema switch
{
OpenApiSchema openApiSchemaTemp => openApiSchemaTemp,
OpenApiSchemaReference openApiSchemaReference => openApiSchemaReference.RecursiveTarget,
_ => throw new ProgrammingError("Unsupported configuration")
};

if (openApiSchema is not null && (context.Type == typeof(T)))
{
// Override schema to be a string
openApiSchema.Type = JsonSchemaType.String;

// Remove properties (e.g., "value")
Contract.Assert(openApiSchema.Properties != null);
openApiSchema.Properties.Clear();
}
}
}
22 changes: 0 additions & 22 deletions src/I/Swagger/INSSSchemaFilter.cs

This file was deleted.

12 changes: 9 additions & 3 deletions src/I/Swagger/PpwOperationFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 by PeopleWare n.v..
// Copyright 2026 by PeopleWare n.v..
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -13,8 +13,9 @@

using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

using PPWCode.Vernacular.Contracts.I;
using PPWCode.Vernacular.Persistence.V;

using Swashbuckle.AspNetCore.SwaggerGen;
Expand Down Expand Up @@ -69,15 +70,20 @@ protected virtual string GetIdentifications(ApiDescription apiDescription, Func<
.Select(GetIdentification));

protected virtual bool ResponseExists(OpenApiOperation operation, string key)
=> operation.Responses.ContainsKey(key);
{
Contract.Requires(operation.Responses is not null);
return operation.Responses.ContainsKey(key);
}

protected virtual void AddResponse(OpenApiOperation operation, string key, OpenApiResponse response)
{
Contract.Requires(operation.Responses is not null);
operation.Responses.Add(key, response);
}

protected virtual void RemoveResponse(OpenApiOperation operation, string key)
{
Contract.Requires(operation.Responses is not null);
if (ResponseExists(operation, key))
{
operation.Responses.Remove(key);
Expand Down
Loading
Loading