Skip to content

Commit 41cb478

Browse files
authored
Add SuperHeadersProcessor to OpenApi (#117)
Introduced the `SuperHeadersProcessor` class to manage required client and developer contact headers for API requests. fixes #116
1 parent 88d32c0 commit 41cb478

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Helldivers-2.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{
5050
.github\ISSUE_TEMPLATE\feature_request.md = .github\ISSUE_TEMPLATE\feature_request.md
5151
EndProjectSection
5252
EndProject
53+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenApi", "OpenApi", "{1A2CFD82-2D8E-4DA3-97A3-403BB478B6EB}"
54+
ProjectSection(SolutionItems) = preProject
55+
docs\openapi\Helldivers-2-API.json = docs\openapi\Helldivers-2-API.json
56+
docs\openapi\Helldivers-2-API_arrowhead.json = docs\openapi\Helldivers-2-API_arrowhead.json
57+
EndProjectSection
58+
EndProject
5359
Global
5460
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5561
Debug|Any CPU = Debug|Any CPU
@@ -91,5 +97,6 @@ Global
9197
{18D4A0EA-02CE-4FEA-A641-848A13603040} = {C0ECDBEB-FC7B-4F3C-AF8F-D0961BD22F61}
9298
{9D663AC9-2CD8-4114-A802-D12284662FF0} = {18D4A0EA-02CE-4FEA-A641-848A13603040}
9399
{FD5B9284-4689-48BE-B520-633C7269F97C} = {18D4A0EA-02CE-4FEA-A641-848A13603040}
100+
{1A2CFD82-2D8E-4DA3-97A3-403BB478B6EB} = {C0ECDBEB-FC7B-4F3C-AF8F-D0961BD22F61}
94101
EndGlobalSection
95102
EndGlobal
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using NSwag;
2+
using NSwag.Generation.Processors;
3+
using NSwag.Generation.Processors.Contexts;
4+
5+
namespace Helldivers.API.OpenApi.OperationProcessors;
6+
7+
/// <summary>
8+
/// The <see cref="SuperHeadersProcessor"/> is used to add headers that are required for the API to identify
9+
/// the client and to provide developer contact information.
10+
/// </summary>
11+
public class SuperHeadersProcessor : IOperationProcessor
12+
{
13+
/// <inheritdoc />
14+
public bool Process(OperationProcessorContext context)
15+
{
16+
context.OperationDescription.Operation.Parameters.Add(
17+
new OpenApiParameter
18+
{
19+
Name = Constants.CLIENT_HEADER_NAME,
20+
Kind = OpenApiParameterKind.Header,
21+
Type = NJsonSchema.JsonObjectType.String,
22+
IsRequired = true,
23+
Description = "The name of the header that identifies the client to the API.",
24+
Default = string.Empty
25+
}
26+
);
27+
28+
context.OperationDescription.Operation.Parameters.Add(
29+
new OpenApiParameter
30+
{
31+
Name = Constants.CONTACT_HEADER_NAME,
32+
Kind = OpenApiParameterKind.Header,
33+
Type = NJsonSchema.JsonObjectType.String,
34+
IsRequired = true,
35+
Description = "The name of the header with developer contact information.",
36+
Default = string.Empty
37+
}
38+
);
39+
40+
return true;
41+
}
42+
}

src/Helldivers-2-API/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Helldivers.API.Controllers.V1;
55
using Helldivers.API.Metrics;
66
using Helldivers.API.Middlewares;
7+
using Helldivers.API.OpenApi.OperationProcessors;
78
using Helldivers.Core.Extensions;
89
using Helldivers.Models;
910
using Helldivers.Models.Domain.Localization;
@@ -162,6 +163,8 @@
162163
new Helldivers.API.OpenApi.TypeMappers.LocalizedMessageTypeMapper(languages)
163164
);
164165

166+
document.OperationProcessors.Add(new SuperHeadersProcessor());
167+
165168
document.DocumentProcessors.Add(new Helldivers.API.OpenApi.DocumentProcessors.HelldiversDocumentProcessor());
166169
});
167170
builder.Services.AddOpenApiDocument(document =>

0 commit comments

Comments
 (0)