Skip to content

Commit 0197e89

Browse files
committed
Update readme
1 parent 9362e11 commit 0197e89

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

ODataModelChangeAnalyzer/ODataModelChangeAnalyzer/IModelChange.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Text;
6+
using System.Text.Json.Serialization;
67
using System.Threading.Tasks;
78

89
namespace ODataModelChangeAnalyzer;
@@ -18,6 +19,7 @@ internal interface IModelChange
1819
public IEdmElement Target { get; }
1920
}
2021

22+
[JsonConverter(typeof(JsonStringEnumConverter))]
2123
internal enum ChangeKind
2224
{
2325
Addition,

ODataModelChangeAnalyzer/ODataModelChangeAnalyzer/Program.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
var changeAnalyzer = new ChangesAnalyzer(originalModel, newModel);
1010
var changes = changeAnalyzer.AnalyzeChanges();
1111

12+
var changesWithLocations = changes.Select(change => new ChangeWithLocation(change, change.Target.Location() as CsdlLocation));
13+
1214
Console.WriteLine("Detected changes:\n");
1315

1416
int count = 0;
17+
1518
foreach (var change in changes)
1619
{
17-
Console.WriteLine(change);
1820
count++;
21+
var location = change.Target.Location() as CsdlLocation;
22+
Console.WriteLine(change);
23+
Console.WriteLine($"At line: {location!.LineNumber} pos: {location!.LinePosition}");
24+
Console.WriteLine();
1925
}
2026

2127
Console.WriteLine($"\nFound {count} changes.");
@@ -28,3 +34,5 @@ IEdmModel ReadModel(string path)
2834
var model = CsdlReader.Parse(xmlReader);
2935
return model;
3036
}
37+
38+
record ChangeWithLocation(object Change, CsdlLocation? Location);

ODataModelChangeAnalyzer/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Sample OData schema change analyzer
2+
3+
Sample analyzer that lists changes between original and updated OData schema using the `IEdmModel`. This can be useful for detecting breaking changes between API versions.
4+
5+
```cli
6+
Detected changes:
7+
8+
StructuredTypePropertyAdded { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.AirportLocation, OriginalType = Microsoft.OData.SampleService.Models.TripPin.AirportLocation, Target = Microsoft.OData.SampleService.Models.TripPin.AirportLocation, ChangeKind = Modification }
9+
At line: 22 pos: 5
10+
11+
SchemaElementAdded { Target = Microsoft.OData.SampleService.Models.TripPin.Picture, ChangeKind = Addition }
12+
At line: 26 pos: 5
13+
14+
StructuredTypeChangedFromOpenToClose { Target = Microsoft.OData.SampleService.Models.TripPin.Person, Original = Microsoft.OData.SampleService.Models.TripPin.Person, ChangeKind = Modification }
15+
At line: 42 pos: 5
16+
17+
StructuredTypePropertyChangedToNonNullable { NewProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, OldProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Person, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Person, Target = Microsoft.OData.SampleService.Models.TripPin.Person, ChangeKind = Modification }
18+
At line: 42 pos: 5
19+
20+
StructuredTypePropertyAdded { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Airline, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Airline, Target = Microsoft.OData.SampleService.Models.TripPin.Airline, ChangeKind = Modification }
21+
At line: 63 pos: 5
22+
23+
StructuredTypePropertyAddedToKey { NewProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, OldProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Airline, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Airline, Target = Microsoft.OData.SampleService.Models.TripPin.Airline, ChangeKind = Modification }
24+
At line: 63 pos: 5
25+
26+
StructuredTypePropertyTypeChanged { NewProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, OldProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Airport, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Airport, Target = Microsoft.OData.SampleService.Models.TripPin.Airport, ChangeKind = Modification }
27+
At line: 75 pos: 5
28+
29+
StructuredTypePropertyRemoved { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Airport, NewType = Microsoft.OData.SampleService.Models.TripPin.Airport, Target = Microsoft.OData.SampleService.Models.TripPin.Airport, ChangeKind = Modification }
30+
At line: 75 pos: 5
31+
32+
StructuredTypePropertyAdded { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.PlanItem, OriginalType = Microsoft.OData.SampleService.Models.TripPin.PlanItem, Target = Microsoft.OData.SampleService.Models.TripPin.PlanItem, ChangeKind = Modification }
33+
At line: 89 pos: 5
34+
35+
StructuredTypePropertyAdded { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.PublicTransportation, OriginalType = Microsoft.OData.SampleService.Models.TripPin.PublicTransportation, Target = Microsoft.OData.SampleService.Models.TripPin.PublicTransportation, ChangeKind = Modification }
36+
At line: 104 pos: 5
37+
38+
StructuredTypePropertyAdded { Property = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Flight, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Flight, Target = Microsoft.OData.SampleService.Models.TripPin.Flight, ChangeKind = Modification }
39+
At line: 107 pos: 5
40+
41+
StructuredTypePropertyDeclaringTypeChanged { NewProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, OldProperty = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsProperty, NewType = Microsoft.OData.SampleService.Models.TripPin.Event, OriginalType = Microsoft.OData.SampleService.Models.TripPin.Event, Target = Microsoft.OData.SampleService.Models.TripPin.Event, ChangeKind = Modification }
42+
At line: 113 pos: 5
43+
44+
SchemaElementRemoved { Target = Microsoft.OData.SampleService.Models.TripPin.Photo, ChangeKind = Deletion }
45+
At line: 25 pos: 5
46+
47+
48+
Found 13 changes.
49+
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
- [.NET's Utf8JsonWriter unnecessary buffer allocations when writing base64 values](./WriteBase64JsonMemoryRepro/)
1010
- [.NET's `JsonSerializer` large memory allocations when serializing large string and byte array values](./JsonSerializerLargeValuesMemoryAllocations/)
1111
- [Sample Data Structure Analysis](./SampleDataStructureAnalysis/)
12+
- [OData schema change analyzer](./ODataModelChangeAnalyzer/)

0 commit comments

Comments
 (0)