|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | + |
| 6 | +namespace Microsoft.OpenApi.Reader.V32 |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Class containing logic to deserialize Open API V32 document into |
| 10 | + /// runtime Open API object model. |
| 11 | + /// </summary> |
| 12 | + internal static partial class OpenApiV32Deserializer |
| 13 | + { |
| 14 | + private static readonly FixedFieldMap<OpenApiComponents> _componentsFixedFields = new() |
| 15 | + { |
| 16 | + {"schemas", (o, n, t) => o.Schemas = n.CreateMap(LoadSchema, t)}, |
| 17 | + {"responses", (o, n, t) => o.Responses = n.CreateMap(LoadResponse, t)}, |
| 18 | + {"parameters", (o, n, t) => o.Parameters = n.CreateMap(LoadParameter, t)}, |
| 19 | + {"examples", (o, n, t) => o.Examples = n.CreateMap(LoadExample, t)}, |
| 20 | + {"requestBodies", (o, n, t) => o.RequestBodies = n.CreateMap(LoadRequestBody, t)}, |
| 21 | + {"headers", (o, n, t) => o.Headers = n.CreateMap(LoadHeader, t)}, |
| 22 | + {"securitySchemes", (o, n, t) => o.SecuritySchemes = n.CreateMap(LoadSecurityScheme, t)}, |
| 23 | + {"links", (o, n, t) => o.Links = n.CreateMap(LoadLink, t)}, |
| 24 | + {"callbacks", (o, n, t) => o.Callbacks = n.CreateMap(LoadCallback, t)}, |
| 25 | + {"pathItems", (o, n, t) => o.PathItems = n.CreateMap(LoadPathItem, t)} |
| 26 | + }; |
| 27 | + |
| 28 | + private static readonly PatternFieldMap<OpenApiComponents> _componentsPatternFields = |
| 29 | + new() |
| 30 | + { |
| 31 | + {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} |
| 32 | + }; |
| 33 | + |
| 34 | + public static OpenApiComponents LoadComponents(ParseNode node, OpenApiDocument hostDocument) |
| 35 | + { |
| 36 | + var mapNode = node.CheckMapNode("components"); |
| 37 | + var components = new OpenApiComponents(); |
| 38 | + |
| 39 | + ParseMap(mapNode, components, _componentsFixedFields, _componentsPatternFields, hostDocument); |
| 40 | + |
| 41 | + return components; |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
0 commit comments