|
6 | 6 | using System.Net; |
7 | 7 | using System.Net.Mime; |
8 | 8 | using System.Text; |
| 9 | +using Azure.DataApiBuilder.Config; |
9 | 10 | using Azure.DataApiBuilder.Config.DatabasePrimitives; |
10 | 11 | using Azure.DataApiBuilder.Config.ObjectModel; |
11 | 12 | using Azure.DataApiBuilder.Core.Authorization; |
@@ -56,13 +57,22 @@ public class OpenApiDocumentor : IOpenApiDocumentor |
56 | 57 | public const string DOCUMENT_CREATION_UNSUPPORTED_ERROR = "OpenAPI description document can't be created when the REST endpoint is disabled globally."; |
57 | 58 | public const string DOCUMENT_CREATION_FAILED_ERROR = "OpenAPI description document creation failed"; |
58 | 59 |
|
| 60 | + public void DocumentorOnConfigChanged(object? sender, HotReloadEventArgs args) |
| 61 | + { |
| 62 | + Console.BackgroundColor = ConsoleColor.Yellow; |
| 63 | + Console.WriteLine($"[OpenApiDocumentor]: Received event with message: {args.Message}"); |
| 64 | + Console.ResetColor(); |
| 65 | + CreateDocument(doOverrideExistingDocument: true); |
| 66 | + } |
| 67 | + |
59 | 68 | /// <summary> |
60 | 69 | /// Constructor denotes required services whose metadata is used to generate the OpenAPI description document. |
61 | 70 | /// </summary> |
62 | 71 | /// <param name="sqlMetadataProvider">Provides database object metadata.</param> |
63 | 72 | /// <param name="runtimeConfigProvider">Provides entity/REST path metadata.</param> |
64 | | - public OpenApiDocumentor(IMetadataProviderFactory metadataProviderFactory, RuntimeConfigProvider runtimeConfigProvider) |
| 73 | + public OpenApiDocumentor(IMetadataProviderFactory metadataProviderFactory, RuntimeConfigProvider runtimeConfigProvider, HotReloadEventHandler<HotReloadEventArgs> handler) |
65 | 74 | { |
| 75 | + handler.DocumentorSubscribe(DocumentorOnConfigChanged); |
66 | 76 | _metadataProviderFactory = metadataProviderFactory; |
67 | 77 | _runtimeConfigProvider = runtimeConfigProvider; |
68 | 78 | _defaultOpenApiResponses = CreateDefaultOpenApiResponses(); |
@@ -100,10 +110,10 @@ public bool TryGetDocument([NotNullWhen(true)] out string? document) |
100 | 110 | /// <exception cref="DataApiBuilderException">Raised when document is already generated |
101 | 111 | /// or a failure occurs during generation.</exception> |
102 | 112 | /// <seealso cref="https://github.com/microsoft/OpenAPI.NET/blob/1.6.3/src/Microsoft.OpenApi/OpenApiSpecVersion.cs"/> |
103 | | - public void CreateDocument() |
| 113 | + public void CreateDocument(bool doOverrideExistingDocument = false) |
104 | 114 | { |
105 | 115 | RuntimeConfig runtimeConfig = _runtimeConfigProvider.GetConfig(); |
106 | | - if (_openApiDocument is not null) |
| 116 | + if (_openApiDocument is not null && !doOverrideExistingDocument) |
107 | 117 | { |
108 | 118 | throw new DataApiBuilderException( |
109 | 119 | message: DOCUMENT_ALREADY_GENERATED_ERROR, |
|
0 commit comments