Skip to content

Commit

Permalink
Merge pull request #572 from radixdlt/cleanup-swagger-ui-page
Browse files Browse the repository at this point in the history
cleanup swagger-ui page. Remove examples and detailed docs and replac…
  • Loading branch information
PawelPawelec-RDX authored Nov 23, 2023
2 parents f7cefbf + dcc18fb commit e246141
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/GatewayApi/OpenApiDocumentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
using RadixDlt.NetworkGateway.GatewayApi.Services;
using RadixDlt.NetworkGateway.GatewayApiSdk.Model;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -98,6 +99,8 @@ public static async Task Handle(
var readResult = await new OpenApiStreamReader().ReadAsync(stream);
var document = readResult.OpenApiDocument;

RemoveRedoclySpecificTags(document.Tags);

document.Servers.Clear();
document.Servers.Add(new OpenApiServer
{
Expand All @@ -122,6 +125,25 @@ public static async Task Handle(
await context.Response.WriteAsync(response, Encoding.UTF8, token);
}

private static void RemoveRedoclySpecificTags(IList<OpenApiTag> tags)
{
var examplesTag = tags.Single(x => x.Name.Equals("Examples", StringComparison.InvariantCultureIgnoreCase));
var architectureTag = tags.Single(x => x.Name.Equals("Architecture", StringComparison.InvariantCultureIgnoreCase));
var conceptsTag = tags.Single(x => x.Name.Equals("Concepts", StringComparison.InvariantCultureIgnoreCase));

tags.Remove(examplesTag);
tags.Remove(architectureTag);
tags.Remove(conceptsTag);

var redoclyLinkTag = new OpenApiTag
{
Name = "Examples + More Docs",
Description = @"Please see the full API documentation in [ReDocly](https://radix-babylon-gateway-api.redoc.ly/) for details about the API abstractions and worked examples for many use cases.",
};

tags.Insert(1, redoclyLinkTag);
}

private static string OptionalReplace(string inputString, string pattern, string? replacement)
{
return replacement == null ? inputString : inputString.Replace(pattern, replacement);
Expand Down

0 comments on commit e246141

Please sign in to comment.