|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | using System.Diagnostics; |
| 5 | +using System.Globalization; |
5 | 6 | using System.Linq; |
6 | 7 | using System.Text.Json; |
7 | 8 | using System.Text.Json.Nodes; |
8 | 9 | using System.Text.Json.Serialization; |
9 | 10 | using Microsoft.AspNetCore.OpenApi; |
10 | 11 | using Microsoft.OpenApi.Models; |
11 | 12 | using Microsoft.OpenApi.Models.Interfaces; |
| 13 | +using Microsoft.OpenApi.Models.References; |
12 | 14 | using OpenApiConstants = Microsoft.AspNetCore.OpenApi.OpenApiConstants; |
13 | 15 |
|
14 | 16 | internal sealed partial class OpenApiJsonSchema |
@@ -256,12 +258,12 @@ public static void ReadProperty(ref Utf8JsonReader reader, string propertyName, |
256 | 258 | case OpenApiSchemaKeywords.MinimumKeyword: |
257 | 259 | reader.Read(); |
258 | 260 | var minimum = reader.GetDecimal(); |
259 | | - schema.Minimum = minimum; |
| 261 | + schema.Minimum = minimum.ToString(CultureInfo.InvariantCulture); |
260 | 262 | break; |
261 | 263 | case OpenApiSchemaKeywords.MaximumKeyword: |
262 | 264 | reader.Read(); |
263 | 265 | var maximum = reader.GetDecimal(); |
264 | | - schema.Maximum = maximum; |
| 266 | + schema.Maximum = maximum.ToString(CultureInfo.InvariantCulture); |
265 | 267 | break; |
266 | 268 | case OpenApiSchemaKeywords.PatternKeyword: |
267 | 269 | reader.Read(); |
@@ -302,25 +304,30 @@ public static void ReadProperty(ref Utf8JsonReader reader, string propertyName, |
302 | 304 | var mappings = ReadDictionary<string>(ref reader); |
303 | 305 | if (mappings is not null) |
304 | 306 | { |
305 | | - schema.Discriminator.Mapping = mappings; |
| 307 | + schema.Discriminator ??= new OpenApiDiscriminator(); |
| 308 | + foreach (var kvp in mappings) |
| 309 | + { |
| 310 | + schema.Discriminator.Mapping ??= []; |
| 311 | + schema.Discriminator.Mapping[kvp.Key] = new OpenApiSchemaReference(kvp.Value); |
| 312 | + } |
306 | 313 | } |
307 | 314 | break; |
308 | 315 | case OpenApiConstants.SchemaId: |
309 | 316 | reader.Read(); |
310 | | - schema.Annotations ??= new Dictionary<string, object>(); |
311 | | - schema.Annotations.Add(OpenApiConstants.SchemaId, reader.GetString()); |
| 317 | + schema.Metadata ??= []; |
| 318 | + schema.Metadata.Add(OpenApiConstants.SchemaId, reader.GetString() ?? string.Empty); |
312 | 319 | break; |
313 | 320 | // OpenAPI does not support the `const` keyword in its schema implementation, so |
314 | 321 | // we map it to its closest approximation, an enum with a single value, here. |
315 | 322 | case OpenApiSchemaKeywords.ConstKeyword: |
316 | 323 | reader.Read(); |
317 | | - schema.Enum = [ReadJsonNode(ref reader, out var constType)]; |
| 324 | + schema.Enum = ReadJsonNode(ref reader, out var constType) is { } jsonNode ? [jsonNode] : []; |
318 | 325 | schema.Type = constType; |
319 | 326 | break; |
320 | 327 | case OpenApiSchemaKeywords.RefKeyword: |
321 | 328 | reader.Read(); |
322 | | - schema.Annotations ??= new Dictionary<string, object>(); |
323 | | - schema.Annotations[OpenApiConstants.RefId] = reader.GetString(); |
| 329 | + schema.Metadata ??= []; |
| 330 | + schema.Metadata[OpenApiConstants.RefId] = reader.GetString() ?? string.Empty; |
324 | 331 | break; |
325 | 332 | default: |
326 | 333 | reader.Skip(); |
|
0 commit comments