| | 1 | | using Asp.Versioning; |
| | 2 | | using Asp.Versioning.Builder; |
| | 3 | | using Gateway.Apis.Amqp.RegistrationExtensions; |
| | 4 | | using Gateway.Apis.Http; |
| | 5 | |
|
| | 6 | | namespace Gateway.Apis; |
| | 7 | |
|
| | 8 | | public record VersionState(ApiVersion Version, bool IsDeprecated); |
| | 9 | |
|
| | 10 | | public static class ApiRegistration |
| | 11 | | { |
| 0 | 12 | | public static readonly VersionState VersionOne = new(new(1.0), true); |
| 0 | 13 | | public static readonly VersionState VersionTwo = new(new(2.0), false); |
| | 14 | |
|
| | 15 | | public static WebApplication UseApis(this WebApplication app) |
| | 16 | | { |
| 0 | 17 | | var versionSet = app.NewApiVersionSet() |
| 0 | 18 | | .AddVersion(VersionOne) |
| 0 | 19 | | .AddVersion(VersionTwo) |
| 0 | 20 | | .Build(); |
| | 21 | |
|
| 0 | 22 | | app.UseHttpApis(versionSet); |
| | 23 | |
|
| 0 | 24 | | return app; |
| | 25 | |
|
| | 26 | | } |
| | 27 | |
|
| | 28 | |
|
| | 29 | | public static WebApplicationBuilder AddApis(this WebApplicationBuilder builder) |
| | 30 | | { |
| 0 | 31 | | builder.AddAsyncApiHost(); |
| 0 | 32 | | return builder; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public static ApiVersionSetBuilder AddVersion(this ApiVersionSetBuilder apiVersionSetBuilder, VersionState versionSt |
| | 36 | | { |
| 0 | 37 | | if (versionState.IsDeprecated) |
| | 38 | | { |
| 0 | 39 | | apiVersionSetBuilder |
| 0 | 40 | | .HasDeprecatedApiVersion(versionState.Version) |
| 0 | 41 | | .AdvertisesDeprecatedApiVersion(versionState.Version); |
| | 42 | | } |
| | 43 | | else |
| | 44 | | { |
| 0 | 45 | | apiVersionSetBuilder |
| 0 | 46 | | .HasApiVersion(versionState.Version) |
| 0 | 47 | | .AdvertisesApiVersion(versionState.Version); |
| | 48 | | } |
| 0 | 49 | | return apiVersionSetBuilder; |
| | 50 | | } |
| | 51 | | } |