This repository was archived by the owner on Jul 2, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdiff.go
More file actions
109 lines (94 loc) · 2.91 KB
/
Copy pathdiff.go
File metadata and controls
109 lines (94 loc) · 2.91 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
package datacontract
import (
"fmt"
"io"
)
func Diff(
dataContractLocation string,
stableDataContractLocation string,
pathToModels, pathToType, pathToSpecification []string,
target io.Writer,
) error {
differences, err := GetDifferences(
dataContractLocation,
stableDataContractLocation,
pathToModels,
pathToType,
pathToSpecification,
)
if err != nil {
return err
}
PrintDifferences(differences, target)
return nil
}
func GetDifferences(
dataContractLocation string,
stableDataContractLocation string,
pathToModels []string,
pathToType []string,
pathToSpecification []string,
) ([]ModelDifference, error) {
localDataContract, err := GetDataContract(dataContractLocation)
if err != nil {
return nil, fmt.Errorf("failed reading local data contract: %w", err)
}
stableDataContract, err := GetDataContract(stableDataContractLocation)
if err != nil {
return nil, fmt.Errorf("failed getting stable data contract: %w", err)
}
stableDataset, err := getModelSpecification(stableDataContract, pathToModels, pathToType, pathToSpecification)
if err != nil {
return nil, fmt.Errorf("failed getting schema specification for stable dataset: %w", err)
}
localDataset, err := getModelSpecification(localDataContract, pathToModels, pathToType, pathToSpecification)
if err != nil {
return nil, fmt.Errorf("failed getting schema specification for local dataset: %w", err)
}
differences := CompareModelSpecifications(*stableDataset, *localDataset)
return differences, nil
}
func getModelSpecification(
contract DataContract,
pathToModels []string,
pathToSchemaType []string,
pathToSchemaSpecification []string,
) (*InternalModelSpecification, error) {
dataset, err := GetModelsFromSpecification(contract, pathToModels)
if dataset == nil {
dataset, err = GetModelSpecificationFromSchema(contract, pathToSchemaType, pathToSchemaSpecification)
}
if dataset == nil {
dataset = &InternalModelSpecification{
Type: "none",
Models: []InternalModel{},
}
}
return dataset, err
}
func PrintDifferences(differences []ModelDifference, target io.Writer) {
Log(target, "Found %v differences between the data contracts!\n", len(differences))
for i, difference := range differences {
Log(target, "\n")
Log(target, "%v Difference %v:\n", severityIcon(difference), i+1)
Log(target, "Description: %v\n", difference.Description)
Log(target, "Type: %v\n", difference.Type)
Log(target, "Severity: %v\n", difference.Severity)
Log(target, "Level: %v\n", difference.Level)
if difference.ModelName != nil {
Log(target, "InternalModel: %v\n", *difference.ModelName)
}
if difference.FieldName != nil {
Log(target, "InternalField: %v\n", *difference.FieldName)
}
}
}
func severityIcon(difference ModelDifference) string {
switch difference.Severity {
case ModelDifferenceSeverityInfo:
return "🟡"
case ModelDifferenceSeverityBreaking:
return "🔴"
}
return ""
}