forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangedAPIResponseBO.cs
59 lines (52 loc) · 2.31 KB
/
ChangedAPIResponseBO.cs
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
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Diff.Enums;
using Microsoft.OpenApi.Diff.Extensions;
using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.Diff.BusinessObjects
{
public class ChangedAPIResponseBO : ComposedChangedBO
{
protected override ChangedElementTypeEnum GetElementType() => ChangedElementTypeEnum.Response;
private readonly OpenApiResponses _oldApiResponses;
private readonly OpenApiResponses _newApiResponses;
private readonly DiffContextBO _context;
public Dictionary<string, OpenApiResponse> Increased { get; set; }
public Dictionary<string, OpenApiResponse> Missing { get; set; }
public Dictionary<string, ChangedResponseBO> Changed { get; set; }
public ChangedExtensionsBO Extensions { get; set; }
public ChangedAPIResponseBO(OpenApiResponses oldApiResponses, OpenApiResponses newApiResponses, DiffContextBO context)
{
_oldApiResponses = oldApiResponses;
_newApiResponses = newApiResponses;
_context = context;
Increased = new Dictionary<string, OpenApiResponse>();
Missing = new Dictionary<string, OpenApiResponse>();
Changed = new Dictionary<string, ChangedResponseBO>();
}
public override List<(string Identifier, ChangedBO Change)> GetChangedElements()
{
return new List<(string Identifier, ChangedBO Change)>(
Changed.Select(x => (x.Key, (ChangedBO)x.Value))
)
{
(null, Extensions)
}
.Where(x => x.Change != null).ToList();
}
public override DiffResultBO IsCoreChanged()
{
if (Increased.IsNullOrEmpty() && Missing.IsNullOrEmpty())
{
return new DiffResultBO(DiffResultEnum.NoChanges);
}
if (!Increased.IsNullOrEmpty() && Missing.IsNullOrEmpty())
{
return new DiffResultBO(DiffResultEnum.Compatible);
}
return new DiffResultBO(DiffResultEnum.Incompatible);
}
protected override List<ChangedInfoBO> GetCoreChanges() =>
GetCoreChangeInfosOfComposed(Increased.Keys.ToList(), Missing.Keys.ToList(), x => x);
}
}