From 7eb03b2a597969d48a1f73f20070679cece04aef Mon Sep 17 00:00:00 2001 From: Ivan Gubanov Date: Fri, 31 Oct 2025 01:19:28 +0200 Subject: [PATCH 1/9] fixed build --- src/Directory.Build.props | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0faceeb..c854181 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -26,11 +26,6 @@ NU1901;NU1902;NU1903;NU1904 - - None - False - - From bd625ea3b7884513573ee8ea29009c140df65ca4 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov Date: Fri, 31 Oct 2025 01:20:09 +0200 Subject: [PATCH 2/9] added new project with json schema generator for rabbit events/types --- ...atform.RabbitMq.JsonSchemaGenerator.csproj | 13 ++++ .../DependencyInjection.cs | 38 ++++++++++++ .../GenerateSchemaMiddleware.cs | 61 +++++++++++++++++++ .../GenerateSchemaOptions.cs | 35 +++++++++++ src/Bss.Platform.sln | 7 +++ src/Directory.Packages.props | 1 + 6 files changed, 155 insertions(+) create mode 100644 src/Bss.Platform.RabbitMq.JsonSchemaGenerator/Bss.Platform.RabbitMq.JsonSchemaGenerator.csproj create mode 100644 src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs create mode 100644 src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs create mode 100644 src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/Bss.Platform.RabbitMq.JsonSchemaGenerator.csproj b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/Bss.Platform.RabbitMq.JsonSchemaGenerator.csproj new file mode 100644 index 0000000..6577468 --- /dev/null +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/Bss.Platform.RabbitMq.JsonSchemaGenerator.csproj @@ -0,0 +1,13 @@ + + + Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator + Bss.Platform.RabbitMq.JsonSchemaGenerator + + + + + + + + + \ No newline at end of file diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs new file mode 100644 index 0000000..4e2e033 --- /dev/null +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace Bss.Platform.RabbitMq.JsonSchemaGenerator; + +public static class DependencyInjection +{ + public static IApplicationBuilder UseRabbitJsonSchemaGenerator( + this IApplicationBuilder app, + Action? setup = null) + { + var options = new GenerateSchemaOptions(); + setup?.Invoke(options); + + var consumedEventMappingFn = options.ManualRegisteredConsumedEventsFn ?? (() => []); + if (options.ExportConsumingTypes) + { + consumedEventMappingFn = () => + { + var manualPassedMessages = options.ManualRegisteredConsumedEventsFn?.Invoke() ?? []; + var autoRegisteredMessages = app.ApplicationServices + .GetKeyedService>(Consumer.DependencyInjection.RoutingMessageProviderKey) ?? []; + + return manualPassedMessages + .Concat(autoRegisteredMessages.Select(x => (x.Key, x.Value))) + .DistinctBy(x => x.Item1, StringComparer.OrdinalIgnoreCase); + }; + } + + var producedEventMappingFn = options.OutputEventMappingFn ?? (() => []); + if (options.ProducedEventTypes != null && options.OutputEventMappingFn == null) + { + producedEventMappingFn = () => options.ProducedEventTypes.Invoke().Select(x => ($"{options.TypePrefix}{x.Name}", x)); + } + + return app.UseMiddleware(options.Path, consumedEventMappingFn, producedEventMappingFn); + } +} diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs new file mode 100644 index 0000000..11a4cf3 --- /dev/null +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs @@ -0,0 +1,61 @@ +using Microsoft.AspNetCore.Http; + +using NJsonSchema; +using NJsonSchema.Generation; + +namespace Bss.Platform.RabbitMq.JsonSchemaGenerator; + +public class GenerateSchemaMiddleware( + RequestDelegate next, + string path, + Func> consumedEventMappingFn, + Func> producedEventMappingFn) +{ + public async Task InvokeAsync(HttpContext context) + { + if (context.Request.Path.Value.Equals(path, StringComparison.InvariantCultureIgnoreCase) + && context.Request.Method == "GET") + { + await this.GenerateSchema(context); + return; + } + + await next(context); + } + + private async Task GenerateSchema(HttpContext context) + { + var settings = new SystemTextJsonSchemaGeneratorSettings + { + FlattenInheritanceHierarchy = true, + GenerateAbstractProperties = false, + AllowReferencesWithProperties = false + }; + + var typeMapping = producedEventMappingFn.Invoke() + .Concat(consumedEventMappingFn.Invoke()) + .ToArray(); + + var schemaContainer = new JsonSchema(); + var appender = new JsonSchemaAppender(schemaContainer, new MappedNameGenerator(typeMapping)); + var generator = new NJsonSchema.Generation.JsonSchemaGenerator(settings); + + var jsonSchemas = typeMapping.Select(x => x.EventType).Select(generator.Generate); + foreach (var schema in jsonSchemas) + { + appender.AppendSchema(schema, null); + } + + context.Response.StatusCode = 200; + context.Response.ContentType = "application/json"; + await context.Response.WriteAsync(schemaContainer.ToJson()); + } +} + +file class MappedNameGenerator(IEnumerable<(string, Type)> sourceMapping) : ITypeNameGenerator +{ + private readonly Dictionary mapping = sourceMapping.ToDictionary(x => x.Item2.Name, x => x.Item1); + + public string Generate(JsonSchema schema, string? typeNameHint, IEnumerable reservedTypeNames) => + this.mapping[schema.Title ?? throw new("JsonSchema title is null")]; +} diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs new file mode 100644 index 0000000..d32ce7c --- /dev/null +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs @@ -0,0 +1,35 @@ +namespace Bss.Platform.RabbitMq.JsonSchemaGenerator; + +public class GenerateSchemaOptions +{ + public string Path { get; set; } = "/api/rabbit-json-schema"; + + /// + /// Enable exporting types for consumed messages registered with method AddPlatformRabbitMqConsumerWithMessages + /// + /// + public bool ExportConsumingTypes { get; set; } = true; + + /// + /// Function to get maps RoutingKey-Type for consuming events registered by old way / handled in processor, + /// work with but with higher priority (by uniq RoutingKey) + /// + /// + public Func>? ManualRegisteredConsumedEventsFn { get; set; } + + /// + /// Function to get produced event types + /// + public Func>? ProducedEventTypes { get; set; } + + /// + /// System prefix for type name + /// + public string TypePrefix { get; set; } = string.Empty; + + /// + /// Function overrides and to manual map + /// RoutingKey/EventName and types + /// + public Func>? OutputEventMappingFn { get; set; } +} diff --git a/src/Bss.Platform.sln b/src/Bss.Platform.sln index f4652d8..1d04266 100644 --- a/src/Bss.Platform.sln +++ b/src/Bss.Platform.sln @@ -40,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notifications", "Notificati EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bss.Platform.Notifications.Audit", "Bss.Platform.Notifications.Audit\Bss.Platform.Notifications.Audit.csproj", "{03CD2FDC-2BF1-497D-BF18-F15170C0AD85}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bss.Platform.RabbitMq.JsonSchemaGenerator", "Bss.Platform.RabbitMq.JsonSchemaGenerator\Bss.Platform.RabbitMq.JsonSchemaGenerator.csproj", "{0FC70E24-62A9-44BF-A433-804C98514A09}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -58,6 +60,7 @@ Global {BE2E219F-3F3B-48E8-B13B-A71321BB6372} = {80AA8C01-842D-4A5F-BCBE-48E0361783A0} {A97421A9-58B7-4948-8231-2028B5D11F36} = {94640F4D-8BC6-407F-835E-73B454972CAD} {03CD2FDC-2BF1-497D-BF18-F15170C0AD85} = {94640F4D-8BC6-407F-835E-73B454972CAD} + {0FC70E24-62A9-44BF-A433-804C98514A09} = {0F54786D-AB46-46AC-88DF-BEB789A62C1F} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {860BFBD8-26EA-44F9-980E-21B828FC8F72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -108,5 +111,9 @@ Global {03CD2FDC-2BF1-497D-BF18-F15170C0AD85}.Debug|Any CPU.Build.0 = Debug|Any CPU {03CD2FDC-2BF1-497D-BF18-F15170C0AD85}.Release|Any CPU.ActiveCfg = Release|Any CPU {03CD2FDC-2BF1-497D-BF18-F15170C0AD85}.Release|Any CPU.Build.0 = Release|Any CPU + {0FC70E24-62A9-44BF-A433-804C98514A09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0FC70E24-62A9-44BF-A433-804C98514A09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0FC70E24-62A9-44BF-A433-804C98514A09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0FC70E24-62A9-44BF-A433-804C98514A09}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 8fb7a7f..e8edfdb 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -9,6 +9,7 @@ + From 3e28f05a4a4b8a6b976c3dd647ce15395cbf00d9 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov Date: Sat, 1 Nov 2025 13:51:52 +0200 Subject: [PATCH 3/9] simplified options/confguration UseRabbitJsonSchemaGenerator --- .../DependencyInjection.cs | 29 +++++++------------ .../GenerateSchemaMiddleware.cs | 27 +++++++---------- .../GenerateSchemaOptions.cs | 24 ++------------- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs index 4e2e033..cd283a0 100644 --- a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs @@ -12,27 +12,18 @@ public static IApplicationBuilder UseRabbitJsonSchemaGenerator( var options = new GenerateSchemaOptions(); setup?.Invoke(options); - var consumedEventMappingFn = options.ManualRegisteredConsumedEventsFn ?? (() => []); - if (options.ExportConsumingTypes) - { - consumedEventMappingFn = () => - { - var manualPassedMessages = options.ManualRegisteredConsumedEventsFn?.Invoke() ?? []; - var autoRegisteredMessages = app.ApplicationServices - .GetKeyedService>(Consumer.DependencyInjection.RoutingMessageProviderKey) ?? []; + var consumedEvents = + app.ApplicationServices + .GetKeyedService>(Consumer.DependencyInjection.RoutingMessageProviderKey) + ?.Select(x => (x.Key, x.Value)) + ?? []; - return manualPassedMessages - .Concat(autoRegisteredMessages.Select(x => (x.Key, x.Value))) - .DistinctBy(x => x.Item1, StringComparer.OrdinalIgnoreCase); - }; - } + var producedEvents = options.ProducedEventTypes.Select(x => ($"{options.TypePrefix}{x.Name}", x)); - var producedEventMappingFn = options.OutputEventMappingFn ?? (() => []); - if (options.ProducedEventTypes != null && options.OutputEventMappingFn == null) - { - producedEventMappingFn = () => options.ProducedEventTypes.Invoke().Select(x => ($"{options.TypePrefix}{x.Name}", x)); - } + var allEventsDict = producedEvents.Concat(consumedEvents) + .DistinctBy(x => x.Item1, StringComparer.OrdinalIgnoreCase) + .ToDictionary(x => x.Item1, x => x.Item2); - return app.UseMiddleware(options.Path, consumedEventMappingFn, producedEventMappingFn); + return app.UseMiddleware(options.Path, allEventsDict); } } diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs index 11a4cf3..2a37277 100644 --- a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaMiddleware.cs @@ -5,16 +5,12 @@ namespace Bss.Platform.RabbitMq.JsonSchemaGenerator; -public class GenerateSchemaMiddleware( - RequestDelegate next, - string path, - Func> consumedEventMappingFn, - Func> producedEventMappingFn) +public class GenerateSchemaMiddleware(RequestDelegate next, string path, Dictionary eventsDict) { public async Task InvokeAsync(HttpContext context) { - if (context.Request.Path.Value.Equals(path, StringComparison.InvariantCultureIgnoreCase) - && context.Request.Method == "GET") + if (context.Request.Method == "GET" + && context.Request.Path.Value.Equals(path, StringComparison.InvariantCultureIgnoreCase)) { await this.GenerateSchema(context); return; @@ -31,16 +27,12 @@ private async Task GenerateSchema(HttpContext context) GenerateAbstractProperties = false, AllowReferencesWithProperties = false }; - - var typeMapping = producedEventMappingFn.Invoke() - .Concat(consumedEventMappingFn.Invoke()) - .ToArray(); - + var schemaContainer = new JsonSchema(); - var appender = new JsonSchemaAppender(schemaContainer, new MappedNameGenerator(typeMapping)); + var appender = new JsonSchemaAppender(schemaContainer, new MappedNameGenerator(eventsDict)); var generator = new NJsonSchema.Generation.JsonSchemaGenerator(settings); - var jsonSchemas = typeMapping.Select(x => x.EventType).Select(generator.Generate); + var jsonSchemas = eventsDict.Select(x => x.Value).Select(generator.Generate); foreach (var schema in jsonSchemas) { appender.AppendSchema(schema, null); @@ -52,10 +44,11 @@ private async Task GenerateSchema(HttpContext context) } } -file class MappedNameGenerator(IEnumerable<(string, Type)> sourceMapping) : ITypeNameGenerator +file class MappedNameGenerator(Dictionary eventsDict) : ITypeNameGenerator { - private readonly Dictionary mapping = sourceMapping.ToDictionary(x => x.Item2.Name, x => x.Item1); + private readonly Dictionary mapping = eventsDict.DistinctBy(x => x.Value) + .ToDictionary(x => x.Value.Name, x => x.Key); public string Generate(JsonSchema schema, string? typeNameHint, IEnumerable reservedTypeNames) => - this.mapping[schema.Title ?? throw new("JsonSchema title is null")]; + this.mapping.GetValueOrDefault(schema.Title ?? throw new("JsonSchema title is null"), schema.Title); } diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs index d32ce7c..e9d33b7 100644 --- a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs @@ -4,32 +4,14 @@ public class GenerateSchemaOptions { public string Path { get; set; } = "/api/rabbit-json-schema"; - /// - /// Enable exporting types for consumed messages registered with method AddPlatformRabbitMqConsumerWithMessages - /// - /// - public bool ExportConsumingTypes { get; set; } = true; - - /// - /// Function to get maps RoutingKey-Type for consuming events registered by old way / handled in processor, - /// work with but with higher priority (by uniq RoutingKey) - /// - /// - public Func>? ManualRegisteredConsumedEventsFn { get; set; } /// - /// Function to get produced event types + /// Collection of produced events /// - public Func>? ProducedEventTypes { get; set; } + public IEnumerable ProducedEventTypes { get; set; } = []; /// - /// System prefix for type name + /// Prefix to add to produced event type /// public string TypePrefix { get; set; } = string.Empty; - - /// - /// Function overrides and to manual map - /// RoutingKey/EventName and types - /// - public Func>? OutputEventMappingFn { get; set; } } From dc1b89f0e1ad1a0dd3945e8bb8311341bd48c8b2 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov Date: Sat, 1 Nov 2025 13:56:29 +0200 Subject: [PATCH 4/9] updated readme --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index c5961d4..cec0d34 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This repository offers a wide collection of .NET packages for use in microservic # Sections - [RabbitMQ Consumer](#Consumer) +- [JsonSchema generator for Rabbit events](#json-schema-generator-for-rabbit-events) - [Logging](#Logging) - [API Middlewares](#Middlewares) - [API Documentation](#Documentation) @@ -159,6 +160,36 @@ services .AddPlatformRabbitMqSqlServerConsumerLock(configuration.GetConnectionString("ms sql connection string")); ``` +### JsonSchema Generator for Rabbit events + +Allow to generate json schema for consuming and producing types, +based on [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) + +To use just add a new middleware via the extension: +```C# +if (app.Environment.IsDevelopment()) +{ + app.UseRabbitJsonSchemaGenerator(opt => + { + opt.Path = "/api/rabbit-json-schema"; + opt.TypePrefix = "TSS"; + opt.ProducedEventTypes = typeof(IEvent).Assembly.GetTypes() + .Where(x => x.IsPublic && !x.IsAbstract && !x.IsInterface) + .Where(x => x.GetInterfaces().Contains(typeof(IEvent))); + }); +} +``` +`TypePrefix` and `ProducedEventTypes` are required only for produced events
+Consumed events are automatically added if you use the new way to register consumer with +method [AddPlatformRabbitMqConsumerWithMessages](#Register-event-with-builder) + +For more complex cases please use middleware without extensions: +```C# +app.UseMiddleware("/api/rabbit-json-schema", allEventsDict); +``` +where `Dictionary allEventsDict` contains the mapping between routing keys and types + + ## Logging To use platform logger, first install the [NuGet package](https://www.nuget.org/packages/Luxoft.Bss.Platform.Logging): From 11c05c57b1cb5e22f46fd7991abf6fba9f05d2c9 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov <75603957+ivan-luxoft@users.noreply.github.com> Date: Sat, 1 Nov 2025 14:02:41 +0200 Subject: [PATCH 5/9] Fix link formatting for JsonSchema generator section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cec0d34..c14f2c9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This repository offers a wide collection of .NET packages for use in microservic # Sections - [RabbitMQ Consumer](#Consumer) -- [JsonSchema generator for Rabbit events](#json-schema-generator-for-rabbit-events) +- [JsonSchema generator for Rabbit events](#jsonschema-generator-for-rabbit-events) - [Logging](#Logging) - [API Middlewares](#Middlewares) - [API Documentation](#Documentation) From ec642b68c55514bfc2d6c5741f1c265e0279a60c Mon Sep 17 00:00:00 2001 From: Ivan Gubanov <75603957+ivan-luxoft@users.noreply.github.com> Date: Sat, 1 Nov 2025 14:05:01 +0200 Subject: [PATCH 6/9] Clarify installation steps for JSON Schema Generator Updated instructions for using the JSON Schema Generator middleware. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c14f2c9..871d8fd 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ services Allow to generate json schema for consuming and producing types, based on [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) -To use just add a new middleware via the extension: +To use just install the [Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator](https://www.nuget.org/packages/Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator) package and add a new middleware via the extension: ```C# if (app.Environment.IsDevelopment()) { From 77ed47063f79afa86ce92491b20b073b8b0093b0 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov <75603957+ivan-luxoft@users.noreply.github.com> Date: Sat, 1 Nov 2025 14:06:44 +0200 Subject: [PATCH 7/9] Fix usage TypePrefix in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 871d8fd..8acf3f8 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ if (app.Environment.IsDevelopment()) app.UseRabbitJsonSchemaGenerator(opt => { opt.Path = "/api/rabbit-json-schema"; - opt.TypePrefix = "TSS"; + opt.TypePrefix = "TSS."; opt.ProducedEventTypes = typeof(IEvent).Assembly.GetTypes() .Where(x => x.IsPublic && !x.IsAbstract && !x.IsInterface) .Where(x => x.GetInterfaces().Contains(typeof(IEvent))); From 2c0ce8fbf1b8cb4f6461b80f31d104adece30f12 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov <75603957+ivan-luxoft@users.noreply.github.com> Date: Sat, 1 Nov 2025 14:16:29 +0200 Subject: [PATCH 8/9] Update README with clearer JsonSchemaGenerator usage Clarified usage instructions for the JsonSchemaGenerator package and middleware. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8acf3f8..46de142 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,9 @@ services Allow to generate json schema for consuming and producing types, based on [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) -To use just install the [Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator](https://www.nuget.org/packages/Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator) package and add a new middleware via the extension: +To use just install +[Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator](https://www.nuget.org/packages/Luxoft.Bss.Platform.RabbitMq.JsonSchemaGenerator) +package and add a new middleware via the extension: ```C# if (app.Environment.IsDevelopment()) { @@ -187,7 +189,8 @@ For more complex cases please use middleware without extensions: ```C# app.UseMiddleware("/api/rabbit-json-schema", allEventsDict); ``` -where `Dictionary allEventsDict` contains the mapping between routing keys and types +where `Dictionary allEventsDict` contains the mapping between routing keys +and types (for both types - consumed and produced) ## Logging From 1f36631077c3da831b9b07e4463612a4a20b8607 Mon Sep 17 00:00:00 2001 From: Ivan Gubanov Date: Mon, 3 Nov 2025 10:51:25 +0200 Subject: [PATCH 9/9] renamed prefix option name, update readme --- README.md | 7 +++++-- .../DependencyInjection.cs | 2 +- .../GenerateSchemaOptions.cs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46de142..e7b9402 100644 --- a/README.md +++ b/README.md @@ -174,14 +174,17 @@ if (app.Environment.IsDevelopment()) app.UseRabbitJsonSchemaGenerator(opt => { opt.Path = "/api/rabbit-json-schema"; - opt.TypePrefix = "TSS."; + opt.SystemPrefix = "TSS."; opt.ProducedEventTypes = typeof(IEvent).Assembly.GetTypes() .Where(x => x.IsPublic && !x.IsAbstract && !x.IsInterface) .Where(x => x.GetInterfaces().Contains(typeof(IEvent))); }); } ``` -`TypePrefix` and `ProducedEventTypes` are required only for produced events
+The next two options are required only for produced events: +- `SystemPrefix` - the prefix added to the produced type names (`SaveEmployee` -> `TSS.SaveEmployee`) when exporting types in the schema +- `ProducedEventTypes` - collection of all produced types, that need to be exported in the schema + Consumed events are automatically added if you use the new way to register consumer with method [AddPlatformRabbitMqConsumerWithMessages](#Register-event-with-builder) diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs index cd283a0..4376982 100644 --- a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/DependencyInjection.cs @@ -18,7 +18,7 @@ public static IApplicationBuilder UseRabbitJsonSchemaGenerator( ?.Select(x => (x.Key, x.Value)) ?? []; - var producedEvents = options.ProducedEventTypes.Select(x => ($"{options.TypePrefix}{x.Name}", x)); + var producedEvents = options.ProducedEventTypes.Select(x => ($"{options.SystemPrefix}{x.Name}", x)); var allEventsDict = producedEvents.Concat(consumedEvents) .DistinctBy(x => x.Item1, StringComparer.OrdinalIgnoreCase) diff --git a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs index e9d33b7..0f83430 100644 --- a/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs +++ b/src/Bss.Platform.RabbitMq.JsonSchemaGenerator/GenerateSchemaOptions.cs @@ -13,5 +13,5 @@ public class GenerateSchemaOptions /// /// Prefix to add to produced event type /// - public string TypePrefix { get; set; } = string.Empty; + public string SystemPrefix { get; set; } = string.Empty; }