Skip to content

Commit dd1bcc7

Browse files
authored
Merge pull request #155 from microsoft/feature/deprecated
adds support for deprecation
2 parents 9f67833 + f738e9f commit dd1bcc7

32 files changed

+5002
-51
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using Microsoft.OData.Edm;
9+
using Microsoft.OData.Edm.Vocabularies;
910
using Microsoft.OpenApi.Models;
1011
using Microsoft.OpenApi.OData.Common;
1112
using Microsoft.OpenApi.OData.Generator;
1213
using Microsoft.OpenApi.OData.Operation;
1314
using Microsoft.OpenApi.OData.PathItem;
1415
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
16+
using Microsoft.OpenApi.OData.Vocabulary.Core;
1517

1618
namespace Microsoft.OpenApi.OData.Edm
1719
{
@@ -171,5 +173,12 @@ private IEnumerable<ODataPath> LoadAllODataPaths()
171173
yield return path;
172174
}
173175
}
176+
internal IEnumerable<DeprecatedRevisionsType> GetDeprecationInformations(IEdmVocabularyAnnotatable annotable)
177+
{
178+
return annotable == null ?
179+
Enumerable.Empty<DeprecatedRevisionsType>() :
180+
(Model?.GetCollection<DeprecatedRevisionsType>(annotable, "Org.OData.Core.V1.Revisions") ??
181+
Enumerable.Empty<DeprecatedRevisionsType>());
182+
}
174183
}
175184
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataDollarCountSegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
8+
using Microsoft.OData.Edm.Vocabularies;
79

810
namespace Microsoft.OpenApi.OData.Edm
911
{
@@ -24,6 +26,12 @@ public class ODataDollarCountSegment : ODataSegment
2426
public override string Identifier => "$count";
2527

2628
/// <inheritdoc />
27-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
29+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
30+
{
31+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
32+
}
33+
34+
/// <inheritdoc />
35+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
2836
}
2937
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataKeySegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using Microsoft.OData.Edm;
10+
using Microsoft.OData.Edm.Vocabularies;
1011
using Microsoft.OpenApi.OData.Common;
1112

1213
namespace Microsoft.OpenApi.OData.Edm
@@ -63,7 +64,13 @@ public override string Identifier
6364
}
6465

6566
/// <inheritdoc />
66-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
67+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
68+
{
69+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
70+
}
71+
72+
/// <inheritdoc />
73+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
6774
{
6875
Utils.CheckArgumentNull(settings, nameof(settings));
6976

src/Microsoft.OpenApi.OData.Reader/Edm/ODataMetadataSegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
8+
using Microsoft.OData.Edm.Vocabularies;
79

810
namespace Microsoft.OpenApi.OData.Edm
911
{
@@ -19,6 +21,12 @@ public class ODataMetadataSegment : ODataSegment
1921
public override string Identifier => "$metadata";
2022

2123
/// <inheritdoc />
22-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$metadata";
24+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
25+
{
26+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
27+
}
28+
29+
/// <inheritdoc />
30+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$metadata";
2331
}
2432
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataNavigationPropertySegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
78
using Microsoft.OData.Edm;
9+
using Microsoft.OData.Edm.Vocabularies;
810
using Microsoft.OpenApi.OData.Common;
911

1012
namespace Microsoft.OpenApi.OData.Edm
@@ -38,6 +40,12 @@ public ODataNavigationPropertySegment(IEdmNavigationProperty navigationProperty)
3840
public override string Identifier { get => NavigationProperty.Name; }
3941

4042
/// <inheritdoc />
41-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationProperty.Name;
43+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
44+
{
45+
return new IEdmVocabularyAnnotatable[] { NavigationProperty, EntityType }.Union(EntityType.FindAllBaseTypes());
46+
}
47+
48+
/// <inheritdoc />
49+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationProperty.Name;
4250
}
4351
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataNavigationSourceSegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
78
using Microsoft.OData.Edm;
9+
using Microsoft.OData.Edm.Vocabularies;
810
using Microsoft.OpenApi.OData.Common;
911

1012
namespace Microsoft.OpenApi.OData.Edm
@@ -38,6 +40,12 @@ public ODataNavigationSourceSegment(IEdmNavigationSource navigationSource)
3840
public override ODataSegmentKind Kind => ODataSegmentKind.NavigationSource;
3941

4042
/// <inheritdoc />
41-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationSource.Name;
43+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
44+
{
45+
return new IEdmVocabularyAnnotatable[] { NavigationSource as IEdmVocabularyAnnotatable, EntityType }.Union(EntityType.FindAllBaseTypes());
46+
}
47+
48+
/// <inheritdoc />
49+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationSource.Name;
4250
}
4351
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationImportSegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Text;
1010
using Microsoft.OData.Edm;
11+
using Microsoft.OData.Edm.Vocabularies;
1112
using Microsoft.OpenApi.OData.Common;
1213

1314
namespace Microsoft.OpenApi.OData.Edm
@@ -54,7 +55,13 @@ public ODataOperationImportSegment(IEdmOperationImport operationImport, IDiction
5455
public override string Identifier { get => OperationImport.Name; }
5556

5657
/// <inheritdoc />
57-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
58+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
59+
{
60+
return new IEdmVocabularyAnnotatable[] { OperationImport };
61+
}
62+
63+
/// <inheritdoc />
64+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
5865
{
5966
Utils.CheckArgumentNull(settings, nameof(settings));
6067

src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Text;
1010
using Microsoft.OData.Edm;
11+
using Microsoft.OData.Edm.Vocabularies;
1112
using Microsoft.OpenApi.OData.Common;
1213

1314
namespace Microsoft.OpenApi.OData.Edm
@@ -169,5 +170,11 @@ private string ActionName(IEdmAction action, OpenApiConvertSettings settings)
169170
return action.FullName();
170171
}
171172
}
172-
}
173+
174+
/// <inheritdoc />
175+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
176+
{
177+
return new IEdmVocabularyAnnotatable[] { Operation };
178+
}
179+
}
173180
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataRefSegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
8+
using Microsoft.OData.Edm.Vocabularies;
79

810
namespace Microsoft.OpenApi.OData.Edm
911
{
@@ -31,6 +33,12 @@ private ODataRefSegment()
3133
public override string Identifier => "$ref";
3234

3335
/// <inheritdoc />
34-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$ref";
36+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
37+
{
38+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
39+
}
40+
41+
/// <inheritdoc />
42+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$ref";
3543
}
3644
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataSegment.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using Microsoft.OData.Edm;
10-
using Microsoft.OpenApi.Models;
1110
using Microsoft.OpenApi.OData.Common;
11+
using Microsoft.OData.Edm.Vocabularies;
12+
using Microsoft.OpenApi.OData.OpenApiExtensions;
1213

1314
namespace Microsoft.OpenApi.OData.Edm
1415
{
@@ -121,5 +122,14 @@ public string GetPathHash(OpenApiConvertSettings settings, ODataPath path = defa
121122
/// <param name="parameters">The existing parameters.</param>
122123
/// <returns>The path item name.</returns>
123124
public abstract string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters);
125+
126+
/// <summary>
127+
/// Provides any deprecation information for the segment.
128+
/// </summary>
129+
public OpenApiDeprecationExtension Deprecation { get; set; }
130+
/// <summary>
131+
/// Returns the list of <see cref="IEdmVocabularyAnnotatable"/> this segment refers to.
132+
/// </summary>
133+
public abstract IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables();
124134
}
125135
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataStreamContentSegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// ------------------------------------------------------------
55

66
using System.Collections.Generic;
7+
using System.Linq;
8+
using Microsoft.OData.Edm.Vocabularies;
79

810
namespace Microsoft.OpenApi.OData.Edm
911
{
@@ -19,6 +21,12 @@ public class ODataStreamContentSegment : ODataSegment
1921
public override string Identifier => "$value";
2022

2123
/// <inheritdoc />
22-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$value";
24+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
25+
{
26+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
27+
}
28+
29+
/// <inheritdoc />
30+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$value";
2331
}
2432
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataStreamPropertySegment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// ------------------------------------------------------------
44

55
using System.Collections.Generic;
6+
using System.Linq;
7+
using Microsoft.OData.Edm.Vocabularies;
68
using Microsoft.OpenApi.OData.Common;
79

810
namespace Microsoft.OpenApi.OData.Edm
@@ -29,6 +31,12 @@ public ODataStreamPropertySegment(string streamPropertyName)
2931
public override string Identifier { get => _streamPropertyName; }
3032

3133
/// <inheritdoc />
32-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => _streamPropertyName;
34+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
35+
{
36+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
37+
}
38+
39+
/// <inheritdoc />
40+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => _streamPropertyName;
3341
}
3442
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using Microsoft.OData.Edm;
8+
using Microsoft.OData.Edm.Vocabularies;
89
using Microsoft.OpenApi.OData.Common;
910

1011
namespace Microsoft.OpenApi.OData.Edm
@@ -33,6 +34,12 @@ public ODataTypeCastSegment(IEdmEntityType entityType)
3334
public override string Identifier { get => EntityType.FullTypeName(); }
3435

3536
/// <inheritdoc />
36-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => EntityType.FullTypeName();
37+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
38+
{
39+
return new IEdmVocabularyAnnotatable[] { EntityType };
40+
}
41+
42+
/// <inheritdoc />
43+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => EntityType.FullTypeName();
3744
}
3845
}

src/Microsoft.OpenApi.OData.Reader/Edm/RecordExpressionExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ public static string GetString(this IEdmRecordExpression record, string property
6969
null;
7070
}
7171

72+
/// <summary>
73+
/// Get the DateTime value from the record using the given property name.
74+
/// </summary>
75+
/// <param name="record">The record expression.</param>
76+
/// <param name="propertyName">The property name.</param>
77+
/// <returns>The DateTime value or null.</returns>
78+
public static DateTime? GetDateTime(this IEdmRecordExpression record, string propertyName)
79+
{
80+
Utils.CheckArgumentNull(record, nameof(record));
81+
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
82+
83+
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
84+
property.Value is IEdmDateConstantExpression value) ?
85+
value.Value :
86+
null;
87+
}
88+
7289
/// <summary>
7390
/// Get the Enum value from the record using the given property name.
7491
/// </summary>

src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public string PathPrefix
203203
/// </summary>
204204
public bool RequireDerivedTypesConstraintForODataTypeCastSegments { get; set; } = true;
205205

206+
/// <summary>
207+
/// Gets/sets a value indicating whether or not to set the deprecated tag for the operation when a revision is present as well as the "x-ms-deprecation" extension with additional information.
208+
/// </summary>
209+
public bool EnableDeprecationInformation { get; set; } = true;
210+
206211
internal OpenApiConvertSettings Clone()
207212
{
208213
var newSettings = new OpenApiConvertSettings
@@ -237,6 +242,7 @@ internal OpenApiConvertSettings Clone()
237242
AddSingleQuotesForStringParameters = this.AddSingleQuotesForStringParameters,
238243
EnableODataTypeCast = this.EnableODataTypeCast,
239244
RequireDerivedTypesConstraintForODataTypeCastSegments = this.RequireDerivedTypesConstraintForODataTypeCastSegments,
245+
EnableDeprecationInformation = this.EnableDeprecationInformation,
240246
};
241247

242248
return newSettings;

0 commit comments

Comments
 (0)