Skip to content

Commit c79d669

Browse files
authored
Add options to override gateway documentation title and openapi information (#247)
* added GatewayDocsTitle and OpenAPI information parameters to GenerateGatewayDocsItself method * Updated readme * Removed extra space Co-authored-by: Kyle Estes <kestes@tigercommissary.com>
1 parent 4082fb0 commit c79d669

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ services.AddSwaggerForOcelot(Configuration,
269269
o.GenerateDocsForGatewayItSelf(opt =>
270270
{
271271
opt.FilePathsForXmlComments = { "MyAPI.xml" };
272+
docGen.GatewayDocsTitle = "My Gateway";
273+
docGen.GatewayDocsOpenApiInfo = new()
274+
{
275+
Title = "My Gateway",
276+
Version = "v1",
277+
};
272278
opt.DocumentFilter<MyDocumentFilter>();
273279
opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
274280
{

src/MMLib.SwaggerForOcelot/Configuration/OcelotGatewayItSelfSwaggerGenOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public OcelotGatewayItSelfSwaggerGenOptions()
2727
/// </summary>
2828
public string[] FilePathsForXmlComments { get; set; }
2929

30+
public string? GatewayDocsTitle { get; set; }
31+
public OpenApiInfo? GatewayDocsOpenApiInfo { get; set; }
32+
3033
internal List<Action<SwaggerGenOptions>> DocumentFilterActions { get; }
3134

3235
internal List<Action<SwaggerGenOptions>> OperationFilterActions { get; }

src/MMLib.SwaggerForOcelot/Configuration/OcelotSwaggerGenOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ public class OcelotSwaggerGenOptions
3333
public void GenerateDocsDocsForGatewayItSelf(Action<OcelotGatewayItSelfSwaggerGenOptions> options = null)
3434
{
3535
GenerateDocsForGatewayItSelf = true;
36-
36+
3737
OcelotGatewayItSelfSwaggerGenOptions = new OcelotGatewayItSelfSwaggerGenOptions();
3838
options?.Invoke(OcelotGatewayItSelfSwaggerGenOptions);
39+
40+
GatewayDocsTitle = OcelotGatewayItSelfSwaggerGenOptions.GatewayDocsTitle ?? GatewayDocsTitle;
41+
GatewayDocsOpenApiInfo = OcelotGatewayItSelfSwaggerGenOptions.GatewayDocsOpenApiInfo ?? GatewayDocsOpenApiInfo;
3942
}
4043

4144
/// <summary>
@@ -61,6 +64,14 @@ public void AddAuthenticationProviderKeyMapping(string authenticationProviderKey
6164

6265
internal const string GatewayKey = "gateway";
6366

67+
internal string GatewayDocsTitle { get; set; } = "Gateway";
68+
69+
internal OpenApiInfo GatewayDocsOpenApiInfo { get; set; } = new()
70+
{
71+
Title = "Gateway",
72+
Version = GatewayKey,
73+
};
74+
6475
internal OcelotGatewayItSelfSwaggerGenOptions OcelotGatewayItSelfSwaggerGenOptions { get; private set; }
6576

6677
internal Dictionary<string, string> AuthenticationProviderKeyMap { get; } = new();

src/MMLib.SwaggerForOcelot/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ private static void AddGatewayItSelfDocs(SwaggerGenOptions c, OcelotSwaggerGenOp
8585
{
8686
if (options.GenerateDocsForGatewayItSelf)
8787
{
88-
c.SwaggerDoc(OcelotSwaggerGenOptions.GatewayKey, new OpenApiInfo
89-
{
90-
Title = "Gateway",
91-
Version = OcelotSwaggerGenOptions.GatewayKey,
92-
});
88+
c.SwaggerDoc(OcelotSwaggerGenOptions.GatewayKey, options.GatewayDocsOpenApiInfo);
9389

9490
if (options.OcelotGatewayItSelfSwaggerGenOptions is not null)
9591
{

src/MMLib.SwaggerForOcelot/Repositories/SwaggerEndPointProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private Dictionary<string, SwaggerEndPointOptions> Init()
4949

5050
if (_options.GenerateDocsForGatewayItSelf)
5151
{
52-
AddEndpoint(ret, OcelotSwaggerGenOptions.GatewayKey, "Gateway");
52+
AddEndpoint(ret, OcelotSwaggerGenOptions.GatewayKey, _options.GatewayDocsTitle);
5353
}
5454

5555
return ret;

0 commit comments

Comments
 (0)