Skip to content

Commit 59455f8

Browse files
authored
[Fix] Adds support for all Org.OData.Core.V1.RevisionKind enum values (#373)
* Rename classes; remove exception throwing in constructor * Update test * Update release notes
1 parent f9e45d0 commit 59455f8

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ private IEnumerable<ODataPath> LoadAllODataPaths()
173173
yield return path;
174174
}
175175
}
176-
internal IEnumerable<DeprecatedRevisionsType> GetDeprecationInformations(IEdmVocabularyAnnotatable annotable)
176+
internal IEnumerable<RevisionRecord> GetDeprecationInformations(IEdmVocabularyAnnotatable annotable)
177177
{
178178
return annotable == null ?
179-
Enumerable.Empty<DeprecatedRevisionsType>() :
180-
(Model?.GetCollection<DeprecatedRevisionsType>(annotable, CoreConstants.Revisions) ??
181-
Enumerable.Empty<DeprecatedRevisionsType>());
179+
Enumerable.Empty<RevisionRecord>() :
180+
(Model?.GetCollection<RevisionRecord>(annotable, CoreConstants.Revisions)?.Where(x => x.Kind == RevisionKind.Deprecated) ??
181+
Enumerable.Empty<RevisionRecord>());
182182
}
183183
}
184184
}

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.4.0-preview2</Version>
18+
<Version>1.4.0-preview3</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
2323
<PackageReleaseNotes>
2424
- DELETE methods should always return response status code #204
2525
- Aliases or strips namespace prefixes from segment names when and where applicable #365
26+
- Adds support for all Org.OData.Core.V1.RevisionKind enum values #372
2627
</PackageReleaseNotes>
2728
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
2829
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/DeprecatedRevisionsType.cs renamed to src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionRecord.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,31 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core;
99
/// Specialized type for Org.OData.Core.V1.Revisions to easily access the additional properties.
1010
/// </summary>
1111
[Term("Org.OData.Core.V1.Revisions")]
12-
internal class DeprecatedRevisionsType : RevisionsType
12+
internal class RevisionRecord : RevisionType
1313
{
1414
/// <summary>
15-
/// The date at which the element has been/will be removed entirely from the service.
15+
/// The date at which the element was/will be added, modified or deprecated from the service.
1616
/// </summary>
1717
public DateTime? RemovalDate { get; private set; }
18+
/// <summary>
19+
/// The date at which the element was/will be be added, modified or deprecated from.
20+
/// </summary>
21+
public DateTime? Date { get; private set; }
1822
/// <summary>
19-
/// The date at which the element has been/will be deprecated.
20-
/// </summary>
21-
public DateTime? Date { get; private set; }
22-
/// <summary>
23-
/// Init the <see cref="DeprecatedRevisionsType"/>.
23+
/// Init the <see cref="RevisionRecord"/>.
2424
/// </summary>
2525
/// <param name="record">The input record.</param>
2626
public override void Initialize(IEdmRecordExpression record)
2727
{
2828
base.Initialize(record);
29-
if (Kind != RevisionKind.Deprecated)
30-
{
31-
throw new InvalidOperationException("The kind of the revision must be Deprecated.");
32-
}
3329
RemovalDate = record.GetDateTime(nameof(RemovalDate));
3430
Date = record.GetDateTime(nameof(Date));
3531
}
36-
/// <summary>
37-
/// Gets a <see cref="OpenApiDeprecationExtension"/> from the current annotation.
38-
/// </summary>
39-
internal OpenApiDeprecationExtension GetOpenApiExtension()
32+
33+
/// <summary>
34+
/// Gets a <see cref="OpenApiDeprecationExtension"/> from the current annotation.
35+
/// </summary>
36+
internal OpenApiDeprecationExtension GetOpenApiExtension()
4037
{
4138
return new OpenApiDeprecationExtension
4239
{

src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionsType.cs renamed to src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core;
99
/// Complex Type: Org.OData.Core.V1.Revisions
1010
/// </summary>
1111
[Term("Org.OData.Core.V1.Revisions")]
12-
internal class RevisionsType : IRecord
12+
internal class RevisionType : IRecord
1313
{
1414
/// <summary>
1515
/// The version this revision was introduced.
@@ -24,7 +24,7 @@ internal class RevisionsType : IRecord
2424
/// </summary>
2525
public string Description { get; private set; }
2626
/// <summary>
27-
/// Init the <see cref="RevisionsType"/>.
27+
/// Init the <see cref="RevisionType"/>.
2828
/// </summary>
2929
/// <param name="record">The input record.</param>
3030
public virtual void Initialize(IEdmRecordExpression record)
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace Microsoft.OpenApi.OData.Reader.Vocabulary.Capabilities.Tests;
1313

14-
public class DeprecatedRevisionTypeTests
14+
public class RevisionRecordTests
1515
{
1616
[Fact]
1717
public void DefaultPropertyAsNull()
1818
{
1919
// Arrange & Act
20-
DeprecatedRevisionsType revision = new();
20+
RevisionRecord revision = new();
2121

2222
// Assert
2323
Assert.Null(revision.Date);
@@ -30,7 +30,7 @@ public void DefaultPropertyAsNull()
3030
public void InitializeWithNullRecordThrows()
3131
{
3232
// Arrange & Act
33-
DeprecatedRevisionsType revision = new();
33+
RevisionRecord revision = new();
3434

3535
// Assert
3636
Assert.Throws<ArgumentNullException>("record", () => revision.Initialize(record: null));
@@ -50,7 +50,7 @@ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess()
5050
new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test")));
5151

5252
// Act
53-
DeprecatedRevisionsType revision = new();
53+
RevisionRecord revision = new();
5454
revision.Initialize(record);
5555

5656
// Assert
@@ -67,20 +67,32 @@ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess()
6767
Assert.Equal(new DateTime(2021, 10, 24), revision.RemovalDate);
6868
}
6969
[Fact]
70-
public void ThrowsOnWrongKind()
70+
public void WorksForAllKinds()
7171
{
7272
// Arrange
73-
IEdmRecordExpression record = new EdmRecordExpression(
73+
IEdmRecordExpression record1 = new EdmRecordExpression(
7474
new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2021, 8, 24))),
7575
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2021, 10, 24))),
7676
new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(addedValue)),
7777
new EdmPropertyConstructor("Description", new EdmStringConstant("The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API.")),
7878
new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test")));
7979

80+
IEdmRecordExpression record2 = new EdmRecordExpression(
81+
new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2023, 3, 2))),
82+
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2023, 05, 30))),
83+
new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(deprecatedValue)),
84+
new EdmPropertyConstructor("Description", new EdmStringConstant("Private preview test.")),
85+
new EdmPropertyConstructor("Version", new EdmStringConstant("2023-03/test")));
86+
8087
// Act
81-
DeprecatedRevisionsType revision = new();
88+
RevisionRecord revision1 = new();
89+
revision1.Initialize(record1);
90+
91+
RevisionRecord revision2 = new();
92+
revision2.Initialize(record2);
8293

8394
// Assert
84-
Assert.Throws<InvalidOperationException>(() => revision.Initialize(record));
95+
Assert.Equal(RevisionKind.Added, revision1.Kind);
96+
Assert.Equal(RevisionKind.Deprecated, revision2.Kind);
8597
}
8698
}

0 commit comments

Comments
 (0)