Extend.OpenApi.Source.Merger 1.0.2

dotnet add package Extend.OpenApi.Source.Merger --version 1.0.2
                    
NuGet\Install-Package Extend.OpenApi.Source.Merger -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Extend.OpenApi.Source.Merger" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Extend.OpenApi.Source.Merger" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Extend.OpenApi.Source.Merger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Extend.OpenApi.Source.Merger --version 1.0.2
                    
#r "nuget: Extend.OpenApi.Source.Merger, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Extend.OpenApi.Source.Merger@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Extend.OpenApi.Source.Merger&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Extend.OpenApi.Source.Merger&version=1.0.2
                    
Install as a Cake Tool

OpenApi.Merger

CI / Publish NuGet NuGet Downloads

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

  1. Ensure each target API serves swagger JSON at the configured URLs.
  2. Edit OpenApi.Merger.Console/appsettings.json to match your services.
  3. 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 FilePath in 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 FilePath is provided the merger loads the file and will not call the ServerUrl/OpenApiPath.

Using the library in your app

  1. Reference OpenApi.Merger from your project.
  2. Register the merger with configuration and DI:
builder.Services.AddOpenApiMerger(builder.Configuration);
  1. 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.

Expose merged JSON via one-line endpoint

You can expose the merged OpenAPI JSON from an ASP.NET Core web project with a single line in Program.cs (ensure you registered the merger with builder.Services.AddOpenApiMerger(builder.Configuration) first):

app.MapGet("/openapi/merged.json", async (OpenApiMerger merger, HttpResponse res) => { res.ContentType = "application/json"; await res.WriteAsync(await merger.MergeMultipleApisAsJsonAsync()); });

This maps /openapi/merged.json to return the merged OpenAPI document as JSON at runtime.

Notes

  • Input format: JSON swagger documents.
  • The merger prefixes conflicting schema names with the API Name and 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 81 2/24/2026
1.0.1 82 2/22/2026