-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOverlayApplicationResult.cs
More file actions
112 lines (104 loc) · 4.46 KB
/
OverlayApplicationResult.cs
File metadata and controls
112 lines (104 loc) · 4.46 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.Text.Json.Nodes;
using BinkyLabs.OpenApi.Overlays.Reader;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Reader;
namespace BinkyLabs.OpenApi.Overlays;
/// <summary>
/// Result of applying overlays to an OpenAPI document
/// </summary>
public class OverlayApplicationResultOfOpenApiDocument : OverlayApplicationResult<OpenApiDocument>
{
internal static OverlayApplicationResultOfOpenApiDocument FromJsonResultWithFailedLoad(OverlayApplicationResultOfJsonNode jsonResult)
{
ArgumentNullException.ThrowIfNull(jsonResult);
return new OverlayApplicationResultOfOpenApiDocument
{
Document = null,
Diagnostic = jsonResult.Diagnostic,
// maintains source format information
OpenApiDiagnostic = jsonResult.OpenApiDiagnostic,
IsSuccessful = false,
};
}
internal static OverlayApplicationResultOfOpenApiDocument FromJsonResult(OverlayApplicationResultOfJsonNode jsonResult, OpenApiDocument? document, OpenApiDiagnostic? openApiDiagnostic)
{
ArgumentNullException.ThrowIfNull(jsonResult);
return new OverlayApplicationResultOfOpenApiDocument
{
Document = document,
Diagnostic = jsonResult.Diagnostic,
// maintains source format information
OpenApiDiagnostic = openApiDiagnostic ?? jsonResult.OpenApiDiagnostic,
IsSuccessful = jsonResult.IsSuccessful,
};
}
}
/// <summary>
/// Result of applying overlays to an OpenAPI document
/// </summary>
public class OverlayApplicationResultOfJsonNode : OverlayApplicationResult<JsonNode>
{
}
/// <summary>
/// Result of applying overlays to an OpenAPI document
/// </summary>
public class OverlayApplicationResult<T>
{
/// <summary>
/// The resulting OpenAPI document after applying overlays, or null if application failed
/// </summary>
public T? Document { get; init; }
/// <summary>
/// Diagnostics from applying the overlays
/// </summary>
public required OverlayDiagnostic Diagnostic { get; init; }
/// <summary>
/// Diagnostics from reading the updated OpenAPI document
/// </summary>
public OpenApiDiagnostic? OpenApiDiagnostic { get; init; }
/// <summary>
/// Indicates whether the overlay application was successful
/// </summary>
public bool IsSuccessful { get; init; }
/// <summary>
/// Deconstructs the OverlayApplicationResult into its components
/// </summary>
/// <param name="document">The resulting OpenAPI document after applying overlays, or null if application failed</param>
/// <param name="diagnostic">Diagnostics from applying the overlays</param>
/// <param name="openApiDiagnostic">Diagnostics from reading the updated OpenAPI document</param>
/// <param name="isSuccessful">Indicates whether the overlay application was successful</param>
public void Deconstruct(out T? document, out OverlayDiagnostic diagnostic, out OpenApiDiagnostic? openApiDiagnostic, out bool isSuccessful)
{
document = Document;
diagnostic = Diagnostic;
openApiDiagnostic = OpenApiDiagnostic;
isSuccessful = IsSuccessful;
}
/// <summary>
/// Deconstructs the OverlayApplicationResult into its components
/// </summary>
/// <param name="document">The resulting OpenAPI document after applying overlays, or null if application failed</param>
/// <param name="diagnostic">Diagnostics from applying the overlays</param>
/// <param name="openApiDiagnostic">Diagnostics from reading the updated OpenAPI document</param>
public void Deconstruct(out T? document, out OverlayDiagnostic diagnostic, out OpenApiDiagnostic? openApiDiagnostic)
{
Deconstruct(out document, out diagnostic, out openApiDiagnostic, out _);
}
/// <summary>
/// Deconstructs the OverlayApplicationResult into its components
/// </summary>
/// <param name="document">The resulting OpenAPI document after applying overlays, or null if application failed</param>
/// <param name="diagnostic">Diagnostics from applying the overlays</param>
public void Deconstruct(out T? document, out OverlayDiagnostic diagnostic)
{
Deconstruct(out document, out diagnostic, out _);
}
/// <summary>
/// Deconstructs the OverlayApplicationResult into its components
/// </summary>
/// <param name="document">The resulting OpenAPI document after applying overlays, or null if application failed</param>
public void Deconstruct(out T? document)
{
Deconstruct(out document, out _);
}
}