|
| 1 | +using ProtoBuf.Grpc.Reflection; |
| 2 | +using ProtoBuf.Meta; |
| 3 | +using System.Text; |
| 4 | +using Cratis.Chronicle.Contracts; |
| 5 | +using Cratis.Chronicle.Contracts.Clients; |
| 6 | +using Cratis.Chronicle.Contracts.Events; |
| 7 | +using Cratis.Chronicle.Contracts.Events.Constraints; |
| 8 | +using Cratis.Chronicle.Contracts.EventSequences; |
| 9 | +using Cratis.Chronicle.Contracts.Host; |
| 10 | +using Cratis.Chronicle.Contracts.Identities; |
| 11 | +using Cratis.Chronicle.Contracts.Jobs; |
| 12 | +using Cratis.Chronicle.Contracts.Observation; |
| 13 | +using Cratis.Chronicle.Contracts.Observation.Reactors; |
| 14 | +using Cratis.Chronicle.Contracts.Observation.Reducers; |
| 15 | +using Cratis.Chronicle.Contracts.Observation.Webhooks; |
| 16 | +using Cratis.Chronicle.Contracts.Projections; |
| 17 | +using Cratis.Chronicle.Contracts.ReadModels; |
| 18 | +using Cratis.Chronicle.Contracts.Recommendations; |
| 19 | +using Cratis.Chronicle.Contracts.Security; |
| 20 | +using Cratis.Chronicle.Contracts.Seeding; |
| 21 | + |
| 22 | +// Group service types by their namespace (package) |
| 23 | +var serviceTypesByPackage = new Dictionary<string, List<Type>> |
| 24 | +{ |
| 25 | + ["Cratis.Chronicle.Contracts"] = new List<Type> { typeof(IEventStores), typeof(INamespaces) }, |
| 26 | + ["Cratis.Chronicle.Contracts.Clients"] = new List<Type> { typeof(IConnectionService) }, |
| 27 | + ["Cratis.Chronicle.Contracts.Events"] = new List<Type> { typeof(IEventTypes) }, |
| 28 | + ["Cratis.Chronicle.Contracts.Events.Constraints"] = new List<Type> { typeof(IConstraints) }, |
| 29 | + ["Cratis.Chronicle.Contracts.EventSequences"] = new List<Type> { typeof(IEventSequences) }, |
| 30 | + ["Cratis.Chronicle.Contracts.Host"] = new List<Type> { typeof(IServer) }, |
| 31 | + ["Cratis.Chronicle.Contracts.Identities"] = new List<Type> { typeof(IIdentities) }, |
| 32 | + ["Cratis.Chronicle.Contracts.Jobs"] = new List<Type> { typeof(IJobs) }, |
| 33 | + ["Cratis.Chronicle.Contracts.Observation"] = new List<Type> { typeof(IObservers), typeof(IFailedPartitions) }, |
| 34 | + ["Cratis.Chronicle.Contracts.Observation.Reactors"] = new List<Type> { typeof(IReactors) }, |
| 35 | + ["Cratis.Chronicle.Contracts.Observation.Reducers"] = new List<Type> { typeof(IReducers) }, |
| 36 | + ["Cratis.Chronicle.Contracts.Observation.Webhooks"] = new List<Type> { typeof(IWebhooks) }, |
| 37 | + ["Cratis.Chronicle.Contracts.Projections"] = new List<Type> { typeof(IProjections) }, |
| 38 | + ["Cratis.Chronicle.Contracts.ReadModels"] = new List<Type> { typeof(IReadModels) }, |
| 39 | + ["Cratis.Chronicle.Contracts.Recommendations"] = new List<Type> { typeof(IRecommendations) }, |
| 40 | + ["Cratis.Chronicle.Contracts.Security"] = new List<Type> { typeof(IApplications), typeof(IUsers) }, |
| 41 | + ["Cratis.Chronicle.Contracts.Seeding"] = new List<Type> { typeof(IEventSeeding) } |
| 42 | +}; |
| 43 | + |
| 44 | +var combinedSchema = new StringBuilder(); |
| 45 | +combinedSchema.AppendLine("syntax = \"proto3\";"); |
| 46 | +combinedSchema.AppendLine(); |
| 47 | + |
| 48 | +foreach (var kvp in serviceTypesByPackage) |
| 49 | +{ |
| 50 | + var generator = new SchemaGenerator |
| 51 | + { |
| 52 | + ProtoSyntax = ProtoSyntax.Proto3 |
| 53 | + }; |
| 54 | + |
| 55 | + try |
| 56 | + { |
| 57 | + var schema = generator.GetSchema(kvp.Value.ToArray()); |
| 58 | + |
| 59 | + // Remove the syntax line from individual schemas as we add it once at the top |
| 60 | + var lines = schema.Split('\n'); |
| 61 | + foreach (var line in lines) |
| 62 | + { |
| 63 | + if (!line.StartsWith("syntax =") && !string.IsNullOrWhiteSpace(line)) |
| 64 | + { |
| 65 | + combinedSchema.AppendLine(line); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + combinedSchema.AppendLine(); |
| 70 | + } |
| 71 | + catch (Exception ex) |
| 72 | + { |
| 73 | + Console.Error.WriteLine($"Error generating schema for package {kvp.Key}: {ex.Message}"); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +Console.WriteLine(combinedSchema.ToString()); |
0 commit comments