Extend.OpenApi.Source.Merger
1.0.1
See the version list below for details.
dotnet add package Extend.OpenApi.Source.Merger --version 1.0.1
NuGet\Install-Package Extend.OpenApi.Source.Merger -Version 1.0.1
<PackageReference Include="Extend.OpenApi.Source.Merger" Version="1.0.1" />
<PackageVersion Include="Extend.OpenApi.Source.Merger" Version="1.0.1" />
<PackageReference Include="Extend.OpenApi.Source.Merger" />
paket add Extend.OpenApi.Source.Merger --version 1.0.1
#r "nuget: Extend.OpenApi.Source.Merger, 1.0.1"
#:package Extend.OpenApi.Source.Merger@1.0.1
#addin nuget:?package=Extend.OpenApi.Source.Merger&version=1.0.1
#tool nuget:?package=Extend.OpenApi.Source.Merger&version=1.0.1
OpenApi.Merger
Merge multiple OpenAPI (Swagger) JSON documents into a single specification. The solution contains a reusable library and a console host that reads configuration, fetches the swagger docs, merges them, and writes output.json.
Projects
- Library:
OpenApi.Merger(core merger logic, DI extension). - Console:
OpenApi.Merger.Console(example runner using the library and configuration).
Configuration
The merger uses the OpenApiMerger section from appsettings.json:
{
"OpenApiMerger": {
"OpenApiTitle": "Merged API",
"OpenApiVersion": "v1",
"OpenApiDescription": "Combined APIs",
"Apis": [
{
"Name": "Api1",
"ServerUrl": "http://localhost:5001",
"PathPrefix": "",
"OpenApiPath": "/swagger/v1/swagger.json"
},
{
"Name": "Api2",
"ServerUrl": "http://localhost:5002",
"PathPrefix": "",
"OpenApiPath": "/swagger/v1/swagger.json"
}
]
}
}
OpenApiTitle,OpenApiVersion,OpenApiDescription: metadata for the merged document.Apis: array of API entries to merge.Name: friendly name used for tag/schema conflict prefixes.ServerUrl: base URL for the API.PathPrefix: prefix added before paths (use empty string if none).OpenApiPath: relative path to the swagger JSON.FilePath(optional): when present the merger will read the OpenAPI JSON from this local file instead of fetching the URL. Paths are resolved relative to the process working directory or may be absolute.
Running the console merger
- Ensure each target API serves swagger JSON at the configured URLs.
- Edit
OpenApi.Merger.Console/appsettings.jsonto match your services. - From the repo root, run:
dotnet run --project OpenApi.Merger.Console/OpenApi.Merger.Console.csproj
The console fetches all configured specs, merges them, and writes output.json in the working directory. It also logs conflicts (e.g., schema name collisions) to the console.
File support
- You can point an API entry at a local OpenAPI JSON file by setting
FilePathin the configuration. This is useful for running the merger in environments where backends are not available or for CI/tests. Example (appsettings.test.json):
{
"OpenApiMerger": {
"OpenApiTitle": "Merged API",
"OpenApiVersion": "v1",
"Apis": [
{ "Name": "Api1", "ServerUrl": "http://localhost:5001", "FilePath": "Resources/api1.json" },
{ "Name": "Api2", "ServerUrl": "http://localhost:5002", "FilePath": "Resources/api2.json" }
]
}
}
- When
FilePathis provided the merger loads the file and will not call theServerUrl/OpenApiPath.
Using the library in your app
- Reference
OpenApi.Mergerfrom your project. - Register the merger with configuration and DI:
builder.Services.AddOpenApiMerger(builder.Configuration);
- Inject and call the merger:
public class MergeRunner(OpenApiMerger merger)
{
public Task<string> RunAsync() => merger.MergeMultipleApisAsJsonAsync();
}
MergeMultipleApisAsJsonAsync returns the merged OpenAPI JSON string. MergeMultipleApisAsync returns the OpenApiDocument if you need to post-process before serialization.
Notes
- Input format: JSON swagger documents.
- The merger prefixes conflicting schema names with the API
Nameand adds tag prefixes<Name>-<Tag>. - Servers are normalized per API using
ServerUrl; ensure the URLs are externally reachable from where you run the merger.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.OpenApi (>= 3.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.