forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenApiV2VersionService.cs
More file actions
73 lines (65 loc) · 2.98 KB
/
OpenApiV2VersionService.cs
File metadata and controls
73 lines (65 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Properties;
using Microsoft.OpenApi.Reader.ParseNodes;
namespace Microsoft.OpenApi.Reader.V2
{
/// <summary>
/// The version specific implementations for OpenAPI V2.0.
/// </summary>
internal class OpenApiV2VersionService : IOpenApiVersionService
{
public OpenApiDiagnostic Diagnostic { get; }
/// <summary>
/// Create Parsing Context
/// </summary>
/// <param name="diagnostic">Provide instance for diagnostic object for collecting and accessing information about the parsing.</param>
public OpenApiV2VersionService(OpenApiDiagnostic diagnostic)
{
Diagnostic = diagnostic;
}
private readonly Dictionary<Type, Func<ParseNode, OpenApiDocument, object?>> _loaders = new()
{
[typeof(OpenApiAny)] = OpenApiV2Deserializer.LoadAny,
[typeof(OpenApiContact)] = OpenApiV2Deserializer.LoadContact,
[typeof(OpenApiExternalDocs)] = OpenApiV2Deserializer.LoadExternalDocs,
[typeof(OpenApiHeader)] = OpenApiV2Deserializer.LoadHeader,
[typeof(OpenApiInfo)] = OpenApiV2Deserializer.LoadInfo,
[typeof(OpenApiLicense)] = OpenApiV2Deserializer.LoadLicense,
[typeof(OpenApiOperation)] = OpenApiV2Deserializer.LoadOperation,
[typeof(OpenApiParameter)] = OpenApiV2Deserializer.LoadParameter,
[typeof(OpenApiPathItem)] = OpenApiV2Deserializer.LoadPathItem,
[typeof(OpenApiPaths)] = OpenApiV2Deserializer.LoadPaths,
[typeof(OpenApiResponse)] = OpenApiV2Deserializer.LoadResponse,
[typeof(OpenApiResponses)] = OpenApiV2Deserializer.LoadResponses,
[typeof(OpenApiSchema)] = OpenApiV2Deserializer.LoadSchema,
[typeof(OpenApiSecurityRequirement)] = OpenApiV2Deserializer.LoadSecurityRequirement,
[typeof(OpenApiSecurityScheme)] = OpenApiV2Deserializer.LoadSecurityScheme,
[typeof(OpenApiTag)] = OpenApiV2Deserializer.LoadTag,
[typeof(OpenApiXml)] = OpenApiV2Deserializer.LoadXml
};
public OpenApiDocument LoadDocument(RootNode rootNode, Uri location)
{
return OpenApiV2Deserializer.LoadOpenApi(rootNode, location);
}
public T? LoadElement<T>(ParseNode node, OpenApiDocument doc) where T : IOpenApiElement
{
if (_loaders.TryGetValue(typeof(T), out var loader) && loader(node, doc) is T result)
{
return result;
}
return default;
}
/// <inheritdoc />
public string GetReferenceScalarValues(MapNode mapNode, string scalarValue)
{
throw new InvalidOperationException();
}
}
}