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
7 changes: 7 additions & 0 deletions Helldivers-2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{
.github\ISSUE_TEMPLATE\feature_request.md = .github\ISSUE_TEMPLATE\feature_request.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenApi", "OpenApi", "{1A2CFD82-2D8E-4DA3-97A3-403BB478B6EB}"
ProjectSection(SolutionItems) = preProject
docs\openapi\Helldivers-2-API.json = docs\openapi\Helldivers-2-API.json
docs\openapi\Helldivers-2-API_arrowhead.json = docs\openapi\Helldivers-2-API_arrowhead.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -91,5 +97,6 @@ Global
{18D4A0EA-02CE-4FEA-A641-848A13603040} = {C0ECDBEB-FC7B-4F3C-AF8F-D0961BD22F61}
{9D663AC9-2CD8-4114-A802-D12284662FF0} = {18D4A0EA-02CE-4FEA-A641-848A13603040}
{FD5B9284-4689-48BE-B520-633C7269F97C} = {18D4A0EA-02CE-4FEA-A641-848A13603040}
{1A2CFD82-2D8E-4DA3-97A3-403BB478B6EB} = {C0ECDBEB-FC7B-4F3C-AF8F-D0961BD22F61}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NSwag;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;

namespace Helldivers.API.OpenApi.OperationProcessors;

/// <summary>
/// The <see cref="SuperHeadersProcessor"/> is used to add headers that are required for the API to identify
/// the client and to provide developer contact information.
/// </summary>
public class SuperHeadersProcessor : IOperationProcessor
{
/// <inheritdoc />
public bool Process(OperationProcessorContext context)
{
context.OperationDescription.Operation.Parameters.Add(
new OpenApiParameter
{
Name = Constants.CLIENT_HEADER_NAME,
Kind = OpenApiParameterKind.Header,
Type = NJsonSchema.JsonObjectType.String,
IsRequired = true,
Description = "The name of the header that identifies the client to the API.",
Default = string.Empty
}
);

context.OperationDescription.Operation.Parameters.Add(
new OpenApiParameter
{
Name = Constants.CONTACT_HEADER_NAME,
Kind = OpenApiParameterKind.Header,
Type = NJsonSchema.JsonObjectType.String,
IsRequired = true,
Description = "The name of the header with developer contact information.",
Default = string.Empty
}
);

return true;
}
}
3 changes: 3 additions & 0 deletions src/Helldivers-2-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Helldivers.API.Controllers.V1;
using Helldivers.API.Metrics;
using Helldivers.API.Middlewares;
using Helldivers.API.OpenApi.OperationProcessors;
using Helldivers.Core.Extensions;
using Helldivers.Models;
using Helldivers.Models.Domain.Localization;
Expand Down Expand Up @@ -162,6 +163,8 @@
new Helldivers.API.OpenApi.TypeMappers.LocalizedMessageTypeMapper(languages)
);

document.OperationProcessors.Add(new SuperHeadersProcessor());

document.DocumentProcessors.Add(new Helldivers.API.OpenApi.DocumentProcessors.HelldiversDocumentProcessor());
});
builder.Services.AddOpenApiDocument(document =>
Expand Down