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
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"isRoot": true,
"tools": {
"swashbuckle.aspnetcore.cli": {
"version": "9.0.1",
"version": "10.0.1",
"commands": [
"swagger"
],
"rollForward": false
},
"csharpier": {
"version": "1.0.2",
"version": "1.2.1",
"commands": [
"csharpier"
],
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.12.0.118525">
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.16.0.128591">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
22 changes: 11 additions & 11 deletions src/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amazon.CloudWatch.EMF" Version="2.2.0" />
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.18.1" />
<PackageReference Include="Elastic.Serilog.Enrichers.Web" Version="8.18.1" />
<PackageReference Include="FluentValidation" Version="12.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.6" />
<PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.6.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.2.0" />
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="9.0.0" />
<PackageReference Include="Elastic.Serilog.Enrichers.Web" Version="9.0.0" />
<PackageReference Include="FluentValidation" Version="12.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.11" />
<PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="9.0.11" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.7.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="9.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="10.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Contracts.csproj" />
Expand Down
10 changes: 4 additions & 6 deletions src/Api/Authentication/PhaJwtAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ IOptions<AclOptions> aclOptions
if (client == null)
return Task.CompletedTask;

claimsIdentity.AddClaims(
[
.. client.Bcps.Select(ClaimTypes.CreateBcpClaim),
.. client.ChedTypes.Select(ClaimTypes.CreateChedTypeClaim),
]
);
claimsIdentity.AddClaims([
.. client.Bcps.Select(ClaimTypes.CreateBcpClaim),
.. client.ChedTypes.Select(ClaimTypes.CreateChedTypeClaim),
]);

context.Principal = new ClaimsPrincipal(claimsIdentity);

Expand Down
4 changes: 2 additions & 2 deletions src/Api/OpenApi/DescriptionSchemaFilter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Defra.PhaImportNotifications.Api.OpenApi;

[ExcludeFromCodeCoverage]
public class DescriptionSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
if (context.ParameterInfo != null)
{
Expand Down
13 changes: 9 additions & 4 deletions src/Api/OpenApi/ExampleValueSchemaFilter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Text.Json.Nodes;
using Defra.PhaImportNotifications.Contracts;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Defra.PhaImportNotifications.Api.OpenApi;

public class ExampleValueSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
var open = schema as OpenApiSchema;

var exampleValueAttributes =
context.MemberInfo?.GetCustomAttributes(false).OfType<ExampleValueAttribute>().ToList() ?? [];

Expand All @@ -20,9 +22,12 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
+ " underlying systems evolve. Consuming clients should cater for this possibility.";

var values = exampleValueAttributes.Select(a => a.Value).Where(v => !string.IsNullOrWhiteSpace(v));

open!.Enum ??= new List<JsonNode>();

foreach (var value in values)
{
schema.Enum.Add(new OpenApiString(value));
open.Enum.Add(value);
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions src/Api/OpenApi/TagsDocumentFilter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using System.Text.Json.Nodes;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Defra.PhaImportNotifications.Api.OpenApi;
Expand All @@ -10,22 +10,23 @@ public class TagsDocumentFilter : IDocumentFilter

public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
swaggerDoc.Extensions["tags"] = new OpenApiArray
var tag = swaggerDoc.Tags?.FirstOrDefault(t => t.Name == ImportNotificationsTag);
if (tag is not null)
{
new OpenApiObject
{
["name"] = new OpenApiString(ImportNotificationsTag),
["description"] = new OpenApiString("Get updated import notifications for a PHA"),
},
};
tag.Description = "Get updated import notifications for a PHA";
}

swaggerDoc.Extensions["x-tagGroups"] = new OpenApiArray
{
new OpenApiObject
swaggerDoc.Extensions ??= new Dictionary<string, IOpenApiExtension>();

swaggerDoc.Extensions["x-tagGroups"] = new JsonNodeExtension(
new JsonArray
{
["name"] = new OpenApiString("Endpoints"),
["tags"] = new OpenApiArray { new OpenApiString(ImportNotificationsTag) },
},
};
new JsonObject
{
["name"] = "Endpoints",
["tags"] = new JsonArray { ImportNotificationsTag },
},
}
);
}
}
18 changes: 5 additions & 13 deletions src/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Serilog;
using Swashbuckle.AspNetCore.SwaggerGen;

Expand Down Expand Up @@ -114,18 +114,10 @@ static void ConfigureWebApplication(WebApplicationBuilder builder, string[] args
},
}
);
c.AddSecurityRequirement(
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oAuth" },
},
[]
},
}
);
c.AddSecurityRequirement(document => new OpenApiSecurityRequirement
{
[new OpenApiSecuritySchemeReference("oAuth", document)] = [],
});
c.IncludeXmlComments(Assembly.GetExecutingAssembly());
c.IncludeXmlComments(typeof(ImportPreNotification).Assembly);
c.DocumentFilter<TagsDocumentFilter>();
Expand Down
158 changes: 79 additions & 79 deletions src/Contracts/CommodityComplements.g.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
#nullable enable
using System.Text.Json.Serialization;
using System.ComponentModel;

namespace Defra.PhaImportNotifications.Contracts;
public partial record CommodityComplements
{
[JsonPropertyName("uniqueComplementId")]
[Description("UUID used to match commodityComplement to its complementParameter set. CHEDPP only")]
public string? UniqueComplementId { get; init; }

[JsonPropertyName("commodityDescription")]
[Description("Description of the commodity")]
public string? CommodityDescription { get; init; }

[JsonPropertyName("commodityId")]
[Description("The unique commodity ID")]
public string? CommodityId { get; init; }

[JsonPropertyName("complementId")]
[Description("Identifier of complement chosen from speciesFamily,speciesClass and speciesType'. This is also used to link to the complementParameterSet")]
public int? ComplementId { get; init; }

[JsonPropertyName("complementName")]
[Description("Represents the lowest granularity - either type, class, family or species name - for the commodity selected. This is also used to drive behaviour for EU Import journeys")]
public string? ComplementName { get; init; }

[JsonPropertyName("eppoCode")]
[Description("EPPO Code related to plant commodities and wood packaging")]
public string? EppoCode { get; init; }

[JsonPropertyName("isWoodPackaging")]
[Description("(Deprecated in IMTA-11832) Is this commodity wood packaging?")]
public bool? IsWoodPackaging { get; init; }

[JsonPropertyName("speciesId")]
[Description("The species ID of the commodity that is imported. Not every commodity has a species ID. This is also used to link to the complementParameterSet. The species ID can change over time")]
public string? SpeciesId { get; init; }

[JsonPropertyName("speciesName")]
[Description("Species name")]
public string? SpeciesName { get; init; }

[JsonPropertyName("speciesNomination")]
[Description("Species nomination")]
public string? SpeciesNomination { get; init; }

[JsonPropertyName("speciesTypeName")]
[Description("Species type name")]
public string? SpeciesTypeName { get; init; }

[JsonPropertyName("speciesType")]
[Description("Species type identifier of commodity")]
public string? SpeciesType { get; init; }

[JsonPropertyName("speciesClassName")]
[Description("Species class name")]
public string? SpeciesClassName { get; init; }

[JsonPropertyName("speciesClass")]
[Description("Species class identifier of commodity")]
public string? SpeciesClass { get; init; }

[JsonPropertyName("speciesFamilyName")]
[Description("Species family name of commodity")]
public string? SpeciesFamilyName { get; init; }

[JsonPropertyName("speciesFamily")]
[Description("Species family identifier of commodity")]
public string? SpeciesFamily { get; init; }

[JsonPropertyName("speciesCommonName")]
[Description("Species common name of commodity for IMP notification simple commodity selection")]
public string? SpeciesCommonName { get; init; }

[JsonPropertyName("isCdsMatched")]
[Description("Has commodity been matched with corresponding CDS declaration")]
public bool? IsCdsMatched { get; init; }
}
#nullable enable
using System.Text.Json.Serialization;
using System.ComponentModel;
namespace Defra.PhaImportNotifications.Contracts;
public partial record CommodityComplements
{
[JsonPropertyName("uniqueComplementId")]
[Description("UUID used to match commodityComplement to its complementParameter set. CHEDPP only")]
public string? UniqueComplementId { get; init; }
[JsonPropertyName("commodityDescription")]
[Description("Description of the commodity")]
public string? CommodityDescription { get; init; }
[JsonPropertyName("commodityId")]
[Description("The unique commodity ID")]
public string? CommodityId { get; init; }
[JsonPropertyName("complementId")]
[Description("Identifier of complement chosen from speciesFamily,speciesClass and speciesType'. This is also used to link to the complementParameterSet")]
public int? ComplementId { get; init; }
[JsonPropertyName("complementName")]
[Description("Represents the lowest granularity - either type, class, family or species name - for the commodity selected. This is also used to drive behaviour for EU Import journeys")]
public string? ComplementName { get; init; }
[JsonPropertyName("eppoCode")]
[Description("EPPO Code related to plant commodities and wood packaging")]
public string? EppoCode { get; init; }
[JsonPropertyName("isWoodPackaging")]
[Description("(Deprecated in IMTA-11832) Is this commodity wood packaging?")]
public bool? IsWoodPackaging { get; init; }
[JsonPropertyName("speciesId")]
[Description("The species ID of the commodity that is imported. Not every commodity has a species ID. This is also used to link to the complementParameterSet. The species ID can change over time")]
public string? SpeciesId { get; init; }
[JsonPropertyName("speciesName")]
[Description("Species name")]
public string? SpeciesName { get; init; }
[JsonPropertyName("speciesNomination")]
[Description("Species nomination")]
public string? SpeciesNomination { get; init; }
[JsonPropertyName("speciesTypeName")]
[Description("Species type name")]
public string? SpeciesTypeName { get; init; }
[JsonPropertyName("speciesType")]
[Description("Species type identifier of commodity")]
public string? SpeciesType { get; init; }
[JsonPropertyName("speciesClassName")]
[Description("Species class name")]
public string? SpeciesClassName { get; init; }
[JsonPropertyName("speciesClass")]
[Description("Species class identifier of commodity")]
public string? SpeciesClass { get; init; }
[JsonPropertyName("speciesFamilyName")]
[Description("Species family name of commodity")]
public string? SpeciesFamilyName { get; init; }
[JsonPropertyName("speciesFamily")]
[Description("Species family identifier of commodity")]
public string? SpeciesFamily { get; init; }
[JsonPropertyName("speciesCommonName")]
[Description("Species common name of commodity for IMP notification simple commodity selection")]
public string? SpeciesCommonName { get; init; }
[JsonPropertyName("isCdsMatched")]
[Description("Has commodity been matched with corresponding CDS declaration")]
public bool? IsCdsMatched { get; init; }
}
Loading
Loading