Skip to content

Commit

Permalink
Add better support for customizing SwaggerUI
Browse files Browse the repository at this point in the history
  • Loading branch information
cguyonnet-sas authored and cguyonnet committed Oct 17, 2022
1 parent 0fec513 commit 35a72bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ app.UseSwaggerForOcelotUI(opt => {
})
```

You can optionally customize SwaggerUI:
```CSharp
app.UseSwaggerForOcelotUI(opt => {
// swaggerForOcelot options
}, uiOpt => {
//swaggerUI options
uiOpt.DocumentTitle = "Gateway documentation";
})
```

6. Show your microservices interactive documentation.

> `http://ocelotserviceurl/swagger`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MMLib.SwaggerForOcelot.Configuration
/// Configuration for Swagger UI.
/// </summary>
/// <seealso cref="Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIOptions" />
public class SwaggerForOcelotUIOptions : SwaggerUIOptions
public class SwaggerForOcelotUIOptions
{
/// <summary>
/// The relative path to gateway swagger generator.
Expand Down
16 changes: 4 additions & 12 deletions src/MMLib.SwaggerForOcelot/Middleware/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ public static class BuilderExtensions
/// </summary>
/// <param name="app">The application builder.</param>
/// <param name="setupAction">Setup <see cref="SwaggerForOcelotUIOptions"/></param>
/// <param name="setupUiAction">Setup SwaggerUI</param>
/// <returns>
/// <see cref="IApplicationBuilder"/>.
/// </returns>
public static IApplicationBuilder UseSwaggerForOcelotUI(
this IApplicationBuilder app,
Action<SwaggerForOcelotUIOptions> setupAction = null)
Action<SwaggerForOcelotUIOptions> setupAction = null,
Action<SwaggerUIOptions> setupUiAction = null)
{
SwaggerForOcelotUIOptions options = app.ApplicationServices.GetService<IOptions<SwaggerForOcelotUIOptions>>().Value;
setupAction?.Invoke(options);
UseSwaggerForOcelot(app, options);

app.UseSwaggerUI(c =>
{
InitUIOption(c, options);
setupUiAction?.Invoke(c);
IReadOnlyList<SwaggerEndPointOptions> endPoints = app
.ApplicationServices.GetService<ISwaggerEndPointProvider>().GetAll();
Expand Down Expand Up @@ -95,15 +97,5 @@ static string GetDescription(SwaggerEndPointConfig config)
}
}
}

private static void InitUIOption(SwaggerUIOptions c, SwaggerForOcelotUIOptions options)
{
c.ConfigObject = options.ConfigObject;
c.DocumentTitle = options.DocumentTitle;
c.HeadContent = options.HeadContent;
c.IndexStream = options.IndexStream;
c.OAuthConfigObject = options.OAuthConfigObject;
c.RoutePrefix = options.RoutePrefix;
}
}
}

0 comments on commit 35a72bc

Please sign in to comment.