|
4 | 4 |
|
5 | 5 | using System.Net.Http.Headers; |
6 | 6 | using System.Text.Json; |
| 7 | +using System.Text.Json.Serialization; |
7 | 8 | using Microsoft.Extensions.Logging; |
8 | 9 |
|
9 | 10 | namespace Elastic.Documentation.Services.Changelog; |
10 | 11 |
|
11 | 12 | /// <summary> |
12 | 13 | /// Service for fetching pull request information from GitHub |
13 | 14 | /// </summary> |
14 | | -public class GitHubPrService(ILoggerFactory loggerFactory) |
| 15 | +public partial class GitHubPrService(ILoggerFactory loggerFactory) |
15 | 16 | { |
16 | 17 | private readonly ILogger<GitHubPrService> _logger = loggerFactory.CreateLogger<GitHubPrService>(); |
17 | 18 | private static readonly HttpClient HttpClient = new(); |
18 | | - private static readonly JsonSerializerOptions JsonOptions = new() |
19 | | - { |
20 | | - PropertyNameCaseInsensitive = true |
21 | | - }; |
22 | 19 |
|
23 | 20 | static GitHubPrService() |
24 | 21 | { |
@@ -63,7 +60,7 @@ static GitHubPrService() |
63 | 60 | } |
64 | 61 |
|
65 | 62 | var jsonContent = await response.Content.ReadAsStringAsync(ctx); |
66 | | - var prData = JsonSerializer.Deserialize<GitHubPrResponse>(jsonContent, JsonOptions); |
| 63 | + var prData = JsonSerializer.Deserialize(jsonContent, GitHubPrJsonContext.Default.GitHubPrResponse); |
67 | 64 |
|
68 | 65 | if (prData == null) |
69 | 66 | { |
@@ -152,6 +149,12 @@ private sealed class GitHubLabel |
152 | 149 | { |
153 | 150 | public string Name { get; set; } = string.Empty; |
154 | 151 | } |
| 152 | + |
| 153 | + [JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)] |
| 154 | + [JsonSerializable(typeof(GitHubPrResponse))] |
| 155 | + [JsonSerializable(typeof(GitHubLabel))] |
| 156 | + [JsonSerializable(typeof(List<GitHubLabel>))] |
| 157 | + private sealed partial class GitHubPrJsonContext : JsonSerializerContext; |
155 | 158 | } |
156 | 159 |
|
157 | 160 | /// <summary> |
|
0 commit comments