Skip to content

Commit

Permalink
docs: add Fly server to swagger (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
lambstream authored Apr 3, 2024
1 parent e5f5953 commit b4d3cc1
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Helldivers-2-API/OpenApi/HelldiversDocumentProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if DEBUG
using NSwag;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;

namespace Helldivers.API.OpenApi;

/// <summary>
/// Handles processing of the OpenAPI specification of the Production Helldivers API.
/// </summary>
public class HelldiversDocumentProcessor : IDocumentProcessor
{
private const string HelldiversFlyServer = "https://helldivers-2-dotnet.fly.dev/";
private const string LocalServer = "/";

/// <inheritdoc />
public void Process(DocumentProcessorContext context)
{
// First we make a copy of the Paths, since C# doesn't like it when collections are modified during iteration.
var paths = context.Document.Paths.ToList();
var server = new OpenApiServer
{
Description = "The dotnet helldivers server",
Url = HelldiversFlyServer
};
var local = new OpenApiServer
{
Description = "The development server",
Url = LocalServer
};

foreach (var (_, item) in paths)
{
item.Servers.Clear();
item.Servers.Add(server);
item.Servers.Add(local);
}
}
}
#endif
2 changes: 2 additions & 0 deletions src/Helldivers-2-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
schema => schema.Type = NJsonSchema.JsonObjectType.String
)
);

document.DocumentProcessors.Add(new Helldivers.API.OpenApi.HelldiversDocumentProcessor());
});
builder.Services.AddOpenApiDocument(document =>
{
Expand Down
180 changes: 180 additions & 0 deletions src/Helldivers-2-API/wwwroot/Helldivers-2-API.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
},
"paths": {
"/raw/api/WarSeason/current/WarID": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand All @@ -29,6 +39,16 @@
}
},
"/raw/api/WarSeason/801/Status": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand All @@ -50,6 +70,16 @@
}
},
"/raw/api/WarSeason/801/WarInfo": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand All @@ -71,6 +101,16 @@
}
},
"/raw/api/Stats/war/801/summary": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand All @@ -92,6 +132,16 @@
}
},
"/raw/api/NewsFeed/801": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand All @@ -116,6 +166,16 @@
}
},
"/raw/api/v2/Assignment/War/801": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"raw"
Expand Down Expand Up @@ -143,6 +203,16 @@
}
},
"/api/v1/war": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -164,6 +234,16 @@
}
},
"/api/v1/assignments": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -188,6 +268,16 @@
}
},
"/api/v1/assignments/{index}": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand Down Expand Up @@ -221,6 +311,16 @@
}
},
"/api/v1/campaigns": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -245,6 +345,16 @@
}
},
"/api/v1/campaigns/{index}": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand Down Expand Up @@ -278,6 +388,16 @@
}
},
"/api/v1/dispatches": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -302,6 +422,16 @@
}
},
"/api/v1/dispatches/{index}": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand Down Expand Up @@ -335,6 +465,16 @@
}
},
"/api/v1/planets": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -359,6 +499,16 @@
}
},
"/api/v1/planets/{index}": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand Down Expand Up @@ -392,6 +542,16 @@
}
},
"/api/v1/planet-events": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -416,6 +576,16 @@
}
},
"/api/v1/steam": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand All @@ -441,6 +611,16 @@
}
},
"/api/v1/steam/{gid}": {
"servers": [
{
"url": "https://helldivers-2-dotnet.fly.dev/",
"description": "The dotnet helldivers server"
},
{
"url": "/",
"description": "The dotnet helldivers server"
}
],
"get": {
"tags": [
"v1"
Expand Down

0 comments on commit b4d3cc1

Please sign in to comment.