| | | 1 | | using System.Text.Json; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | using Elsa.Api.Client.Converters; |
| | | 4 | | using Refit; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Api.Client; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Contains helper methods for configuring Refit settings. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class RefitSettingsHelper |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Creates a <see cref="RefitSettings"/> instance configured for Elsa. |
| | | 15 | | /// </summary> |
| | | 16 | | public static RefitSettings CreateRefitSettings(IServiceProvider serviceProvider, Action<IServiceProvider, JsonSeria |
| | | 17 | | { |
| | 14 | 18 | | var settings = new RefitSettings |
| | 14 | 19 | | { |
| | 14 | 20 | | ContentSerializer = new SystemTextJsonContentSerializer(CreateJsonSerializerOptions(serviceProvider, configu |
| | 14 | 21 | | }; |
| | | 22 | | |
| | 14 | 23 | | return settings; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Creates a <see cref="JsonSerializerOptions"/> instance configured for Elsa. |
| | | 28 | | /// </summary> |
| | | 29 | | public static JsonSerializerOptions CreateJsonSerializerOptions(IServiceProvider serviceProvider, Action<IServicePro |
| | | 30 | | { |
| | 25 | 31 | | var options = new JsonSerializerOptions |
| | 25 | 32 | | { |
| | 25 | 33 | | PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
| | 25 | 34 | | }; |
| | | 35 | | |
| | 25 | 36 | | options.Converters.Add(new JsonStringEnumConverter()); |
| | 25 | 37 | | options.Converters.Add(new VersionOptionsJsonConverter()); |
| | 25 | 38 | | options.Converters.Add(new TypeJsonConverter()); |
| | | 39 | | |
| | 25 | 40 | | configureJsonSerializerOptions?.Invoke(serviceProvider, options); |
| | | 41 | | |
| | 25 | 42 | | return options; |
| | | 43 | | } |
| | | 44 | | } |