-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.On BuilderExtensions.cs AddSwaggerEndPoints method InvalidOperation…
…Exception throwing block refactored using IEndPointValidator.cs 2. created custom OnChange instead of IOptionsMonitor.OnChange to monipulate with Options which added Programmatically and don't effect to config options. Both works well
- Loading branch information
1 parent
da22005
commit 3d16d55
Showing
16 changed files
with
418 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
src/MMLib.SwaggerForOcelot/Repositories/EndPointValidators/ConsulEndPointValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System.Collections.Generic; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories.EndPointValidators; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class ConsulEndPointValidator : IEndPointValidator | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="endPoints"></param> | ||
public void Validate(IReadOnlyList<SwaggerEndPointOptions> endPoints) | ||
{ | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/MMLib.SwaggerForOcelot/Repositories/EndPointValidators/EndPointValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories.EndPointValidators; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class EndPointValidator : IEndPointValidator | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="endPoints"></param> | ||
public void Validate(IReadOnlyList<SwaggerEndPointOptions> endPoints) | ||
{ | ||
if (endPoints is null || endPoints.Count == 0) | ||
{ | ||
throw new InvalidOperationException( | ||
$"{SwaggerEndPointOptions.ConfigurationSectionName} configuration section is missing or empty."); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/MMLib.SwaggerForOcelot/Repositories/EndPointValidators/IEndPointValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System.Collections.Generic; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories.EndPointValidators; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IEndPointValidator | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="endPoints"></param> | ||
void Validate(IReadOnlyList<SwaggerEndPointOptions> endPoints); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/MMLib.SwaggerForOcelot/Repositories/EndPointsMonitor/ConsulSwaggerEndpointsMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#nullable enable | ||
using Microsoft.Extensions.Options; | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using Swashbuckle.AspNetCore.Swagger; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class ConsulSwaggerEndpointsMonitor : ISwaggerEndpointsMonitor | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
private readonly IOptionsMonitor<List<SwaggerEndPointOptions>> _optionsMonitor; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
private readonly IConsulEndpointOptionsMonitor _consulOptionsMonitor; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public event EventHandler<List<SwaggerEndPointOptions>> OptionsChanged; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="optionsMonitor"></param> | ||
/// <param name="consulOptionsMonitor"></param> | ||
public ConsulSwaggerEndpointsMonitor(IOptionsMonitor<List<SwaggerEndPointOptions>> optionsMonitor, | ||
Check warning on line 36 in src/MMLib.SwaggerForOcelot/Repositories/EndPointsMonitor/ConsulSwaggerEndpointsMonitor.cs GitHub Actions / build-and-test
|
||
IConsulEndpointOptionsMonitor consulOptionsMonitor) | ||
{ | ||
_optionsMonitor = optionsMonitor; | ||
_consulOptionsMonitor = consulOptionsMonitor; | ||
_optionsMonitor.OnChange(ConfigChanged); | ||
_consulOptionsMonitor.OptionsChanged +=(s,e) => ConfigChanged(e); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="configOptions"></param> | ||
/// <returns></returns> | ||
private void ConfigChanged(List<SwaggerEndPointOptions> configOptions) | ||
{ | ||
var options = ConcatOptions(_optionsMonitor.CurrentValue, _consulOptionsMonitor.CurrentValue); | ||
CallOptionsChanged(options); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="configOptions"></param> | ||
/// <param name="localOptions"></param> | ||
/// <returns></returns> | ||
protected virtual List<SwaggerEndPointOptions> ConcatOptions(List<SwaggerEndPointOptions> configOptions, | ||
List<SwaggerEndPointOptions> localOptions) | ||
{ | ||
return configOptions | ||
.Concat(localOptions) | ||
.DistinctBy(s => s.Key) | ||
.ToList(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
protected virtual void CallOptionsChanged(List<SwaggerEndPointOptions> options) | ||
{ | ||
OptionsChanged?.Invoke(this, options); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/MMLib.SwaggerForOcelot/Repositories/EndPointsMonitor/ISwaggerEndpointsMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface ISwaggerEndpointsMonitor | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
event EventHandler<List<SwaggerEndPointOptions>> OptionsChanged; | ||
} |
52 changes: 52 additions & 0 deletions
52
src/MMLib.SwaggerForOcelot/Repositories/EndPointsMonitor/SwaggerEndpointsMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#nullable enable | ||
using Microsoft.Extensions.Options; | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MMLib.SwaggerForOcelot.Repositories; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class SwaggerEndpointsMonitor : ISwaggerEndpointsMonitor | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
private readonly IOptionsMonitor<List<SwaggerEndPointOptions>> _optionsMonitor; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public event EventHandler<List<SwaggerEndPointOptions>> OptionsChanged; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="optionsMonitor"></param> | ||
public SwaggerEndpointsMonitor(IOptionsMonitor<List<SwaggerEndPointOptions>> optionsMonitor) | ||
Check warning on line 28 in src/MMLib.SwaggerForOcelot/Repositories/EndPointsMonitor/SwaggerEndpointsMonitor.cs GitHub Actions / build-and-test
|
||
{ | ||
_optionsMonitor = optionsMonitor; | ||
_optionsMonitor.OnChange(ConfigChanged); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="configOptions"></param> | ||
/// <returns></returns> | ||
private void ConfigChanged(List<SwaggerEndPointOptions> configOptions) | ||
{ | ||
CallOptionsChanged(_optionsMonitor.CurrentValue); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
protected virtual void CallOptionsChanged(List<SwaggerEndPointOptions> options) | ||
{ | ||
OptionsChanged?.Invoke(this, options); | ||
} | ||
} |
Oops, something went wrong.