From 1cac7c3e4090135b3f721f5ec02282d3a8c34abb Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Mon, 27 Nov 2023 20:13:03 +0100 Subject: [PATCH] Extend websocket swagger documentation (#34) --- GuildWarsPartySearch/Launch/Program.cs | 2 +- .../WebSocketEndpointsDocumentFilter.cs | 88 ++++++++++++++++++- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/GuildWarsPartySearch/Launch/Program.cs b/GuildWarsPartySearch/Launch/Program.cs index 22b9c87..cff2cc4 100644 --- a/GuildWarsPartySearch/Launch/Program.cs +++ b/GuildWarsPartySearch/Launch/Program.cs @@ -11,7 +11,7 @@ namespace GuildWarsPartySearch.Server.Launch; public class Program { - public static CancellationTokenSource CancellationTokenSource = new(); + public static readonly CancellationTokenSource CancellationTokenSource = new(); private static async Task Main() { diff --git a/GuildWarsPartySearch/Launch/WebSocketEndpointsDocumentFilter.cs b/GuildWarsPartySearch/Launch/WebSocketEndpointsDocumentFilter.cs index a44a0f3..769b92c 100644 --- a/GuildWarsPartySearch/Launch/WebSocketEndpointsDocumentFilter.cs +++ b/GuildWarsPartySearch/Launch/WebSocketEndpointsDocumentFilter.cs @@ -26,7 +26,55 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) Name = "PartySearch" } }, - Description = "WebSocket endpoint for live feed.", + Description = @" +WebSocket endpoint for live feed. + +Sends periodic party search updates. Example: +```json +{ + ""Searches"": + [ + { + ""Campaign"":""Prophecies"", + ""Continent"":""Tyria"", + ""Region"":""Kryta"", + ""Map"":""Lions Arch"", + ""District"":""En - 1"", + ""PartySearchEntries"": + [ + { + ""CharName"":""Shiro Tagachi"", + ""PartySize"":8, + ""PartyMaxSize"":8, + ""Npcs"":0 + }, + { + ""CharName"":""Kormir Sucks"", + ""PartySize"":8, + ""PartyMaxSize"":8, + ""Npcs"":0 + } + ] + }, + { + ""Campaign"":""Prophecies"", + ""Continent"":""Tyria"", + ""Region"":""Kryta"", + ""Map"":""Warrior's Isle"", + ""District"":""En - 1"", + ""PartySearchEntries"": + [ + { + ""CharName"":""Don Abaddon"", + ""PartySize"":0, + ""PartyMaxSize"":16, + ""Npcs"":2 + } + ] + } + ] +} +```", Responses = new OpenApiResponses { { "200", new OpenApiResponse(){ Description = "Success" } }, @@ -78,7 +126,43 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) Name = "PartySearch" } }, - Description = $"WebSocket endpoint for posting party search updates. Protected by {ApiKeyProtected.ApiKeyHeader} header.", + Description = @$" +WebSocket endpoint for posting party search updates. + +Protected by *{ApiKeyProtected.ApiKeyHeader}* header. + +Accepts json payloads. Example: +```json +{{ + ""Continent"": ""Tyria"", + ""Campaign"": ""Prophecies"", + ""Region"": ""Kryta"", + ""Map"": 4, + ""District"": ""En - 1"", + ""PartySearchEntries"": [ + {{ + ""PartySize"": 8, + ""PartyMaxSize"": 8, + ""Npcs"": 0, + ""CharName"": ""Shiro Tagachi"", + }}, + {{ + ""PartySize"": 8, + ""PartyMaxSize"": 8, + ""Npcs"": 0, + ""CharName"": ""Kormir Sucks"", + }} + ] +}} +``` + +Returns json payloads. Example: +```json +{{ + ""Result"": 0, + ""Description"": ""Success"" +}} +```", Responses = new OpenApiResponses { { "200", new OpenApiResponse(){ Description = "Success" } },