Skip to content

Commit 81d7716

Browse files
committed
feat: update version to 1.0.16 and enhance README with configuration options for OpenAPI UI middleware
1 parent 2e0fd7d commit 81d7716

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

src/c-sharp/JakubKozera.OpenApiUi/JakubKozera.OpenApiUi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
44
<PackageId>JakubKozera.OpenApiUi</PackageId>
5-
<Version>1.0.15</Version>
5+
<Version>1.0.16</Version>
66
<Authors>Jakub Kozera</Authors>
77
<Description>A .NET library serving OpenAPI UI with HTML/CSS</Description>
88
<PackageTags>openapi;ui;html;css;dotnet</PackageTags>

src/c-sharp/JakubKozera.OpenApiUi/Lib/OpenApiUiMiddleware.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ public static IApplicationBuilder UseOpenApiUi(this IApplicationBuilder app, Ope
9090
return app;
9191
}
9292

93+
/// <summary>
94+
/// Adds OpenAPI UI middleware to the ASP.NET Core application pipeline with a configuration action.
95+
/// This middleware serves an embedded OpenAPI documentation interface.
96+
/// </summary>
97+
/// <param name="app">The application builder instance.</param>
98+
/// <param name="configureOptions">An action to configure the OpenAPI UI options.</param>
99+
/// <returns>The application builder instance for method chaining.</returns>
100+
public static IApplicationBuilder UseOpenApiUi(this IApplicationBuilder app, Action<OpenApiUiConfiguration> configureOptions)
101+
{
102+
if (configureOptions == null)
103+
throw new ArgumentNullException(nameof(configureOptions));
104+
105+
var configuration = new OpenApiUiConfiguration();
106+
configureOptions(configuration);
107+
return UseOpenApiUi(app, configuration);
108+
}
109+
93110
/// <summary>
94111
/// Adds OpenAPI UI middleware to the ASP.NET Core application pipeline with default configuration.
95112
/// This middleware serves an embedded OpenAPI documentation interface.

src/c-sharp/JakubKozera.OpenApiUi/README.md

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,52 @@ app.Run();
104104

105105
### 2. Access the OpenAPI UI
106106

107-
Navigate to `/openapi-ui` in your browser to view the API documentation interface.
107+
Navigate to `/openapi-ui` in your browser to view the API documentation interface (or your custom path if configured).
108+
109+
**Note:** The default UI path is `/openapi-ui` and the default OpenAPI specification path is `/swagger/v1/swagger.json`.
108110

109111
## Configuration
110112

111-
### Custom OpenAPI Specification Path
113+
### Basic Configuration Options
114+
115+
The middleware provides several overloads for different configuration needs:
116+
117+
#### Default Configuration
118+
119+
```csharp
120+
app.UseOpenApiUi(); // Uses default settings
121+
```
122+
123+
**Default values:**
124+
125+
- `OpenApiSpecPath`: `"/swagger/v1/swagger.json"`
126+
- `OpenApiUiPath`: `"openapi-ui"`
127+
128+
#### Simple Path Configuration
129+
130+
```csharp
131+
app.UseOpenApiUi("/api/docs/swagger.json"); // Custom OpenAPI spec path only
132+
```
133+
134+
#### Fluent Configuration
135+
136+
```csharp
137+
app.UseOpenApiUi(config =>
138+
{
139+
config.OpenApiSpecPath = "/api/v2/openapi.json"; // Custom spec path
140+
config.OpenApiUiPath = "api-docs"; // Custom UI path
141+
});
142+
```
112143

113-
You can specify a custom path to your OpenAPI specification:
144+
#### Configuration Object
114145

115146
```csharp
116-
app.UseOpenApiUi("/api/docs/swagger.json");
147+
var configuration = new OpenApiUiConfiguration
148+
{
149+
OpenApiSpecPath = "/api/docs/swagger.json",
150+
OpenApiUiPath = "docs"
151+
};
152+
app.UseOpenApiUi(configuration);
117153
```
118154

119155
## Usage Examples
@@ -140,8 +176,11 @@ var app = builder.Build();
140176
// add OpenUI specification
141177
app.UseSwagger();
142178

143-
// add OpenAPI UI
144-
app.UseOpenApiUi();
179+
// add OpenAPI UI with custom configuration
180+
app.UseOpenApiUi(config =>
181+
{
182+
config.OpenApiUiPath = "api-docs"; // Access via /api-docs instead of default /openapi-ui
183+
});
145184

146185
app.UseHttpsRedirection();
147186
app.UseAuthorization();
@@ -150,6 +189,33 @@ app.MapControllers();
150189
app.Run();
151190
```
152191

192+
### Advanced Configuration
193+
194+
```csharp
195+
// Custom path and specification
196+
app.UseOpenApiUi(config =>
197+
{
198+
config.OpenApiSpecPath = "/api/v2/openapi.json"; // Different spec location
199+
config.OpenApiUiPath = "documentation"; // Custom UI path
200+
});
201+
202+
// Multiple API versions
203+
if (app.Environment.IsDevelopment())
204+
{
205+
app.UseOpenApiUi(config =>
206+
{
207+
config.OpenApiSpecPath = "/swagger/v1/swagger.json";
208+
config.OpenApiUiPath = "docs/v1";
209+
});
210+
211+
app.UseOpenApiUi(config =>
212+
{
213+
config.OpenApiSpecPath = "/swagger/v2/swagger.json";
214+
config.OpenApiUiPath = "docs/v2";
215+
});
216+
}
217+
```
218+
153219
## Requirements
154220

155221
- .NET 6.0, 8.0, or 9.0

0 commit comments

Comments
 (0)