diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs index 63841a68..e7fab01a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs @@ -173,12 +173,12 @@ private IEnumerable LoadAllODataPaths() yield return path; } } - internal IEnumerable GetDeprecationInformations(IEdmVocabularyAnnotatable annotable) + internal IEnumerable GetDeprecationInformations(IEdmVocabularyAnnotatable annotable) { return annotable == null ? - Enumerable.Empty() : - (Model?.GetCollection(annotable, CoreConstants.Revisions) ?? - Enumerable.Empty()); + Enumerable.Empty() : + (Model?.GetCollection(annotable, CoreConstants.Revisions)?.Where(x => x.Kind == RevisionKind.Deprecated) ?? + Enumerable.Empty()); } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj index 2fbe8f44..520063e0 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,7 +15,7 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.4.0-preview2 + 1.4.0-preview3 This package contains the codes you need to convert OData CSDL to Open API Document of Model. © Microsoft Corporation. All rights reserved. Microsoft OpenApi OData EDM @@ -23,6 +23,7 @@ - DELETE methods should always return response status code #204 - Aliases or strips namespace prefixes from segment names when and where applicable #365 +- Adds support for all Org.OData.Core.V1.RevisionKind enum values #372 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/DeprecatedRevisionsType.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionRecord.cs similarity index 57% rename from src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/DeprecatedRevisionsType.cs rename to src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionRecord.cs index 0ff08d71..b0694845 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/DeprecatedRevisionsType.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionRecord.cs @@ -9,34 +9,31 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core; /// Specialized type for Org.OData.Core.V1.Revisions to easily access the additional properties. /// [Term("Org.OData.Core.V1.Revisions")] -internal class DeprecatedRevisionsType : RevisionsType +internal class RevisionRecord : RevisionType { /// - /// The date at which the element has been/will be removed entirely from the service. + /// The date at which the element was/will be added, modified or deprecated from the service. /// public DateTime? RemovalDate { get; private set; } + /// + /// The date at which the element was/will be be added, modified or deprecated from. + /// + public DateTime? Date { get; private set; } /// - /// The date at which the element has been/will be deprecated. - /// - public DateTime? Date { get; private set; } - /// - /// Init the . + /// Init the . /// /// The input record. public override void Initialize(IEdmRecordExpression record) { base.Initialize(record); - if (Kind != RevisionKind.Deprecated) - { - throw new InvalidOperationException("The kind of the revision must be Deprecated."); - } RemovalDate = record.GetDateTime(nameof(RemovalDate)); Date = record.GetDateTime(nameof(Date)); } - /// - /// Gets a from the current annotation. - /// - internal OpenApiDeprecationExtension GetOpenApiExtension() + + /// + /// Gets a from the current annotation. + /// + internal OpenApiDeprecationExtension GetOpenApiExtension() { return new OpenApiDeprecationExtension { diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionsType.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionType.cs similarity index 92% rename from src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionsType.cs rename to src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionType.cs index b8ad355c..c530f8cd 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionsType.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Core/RevisionType.cs @@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core; /// Complex Type: Org.OData.Core.V1.Revisions /// [Term("Org.OData.Core.V1.Revisions")] -internal class RevisionsType : IRecord +internal class RevisionType : IRecord { /// /// The version this revision was introduced. @@ -24,7 +24,7 @@ internal class RevisionsType : IRecord /// public string Description { get; private set; } /// - /// Init the . + /// Init the . /// /// The input record. public virtual void Initialize(IEdmRecordExpression record) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/DeprecatedRevisionTypeTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/RevisionRecordTests.cs similarity index 75% rename from test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/DeprecatedRevisionTypeTests.cs rename to test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/RevisionRecordTests.cs index 1e799986..3b155d23 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/DeprecatedRevisionTypeTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/RevisionRecordTests.cs @@ -11,13 +11,13 @@ namespace Microsoft.OpenApi.OData.Reader.Vocabulary.Capabilities.Tests; -public class DeprecatedRevisionTypeTests +public class RevisionRecordTests { [Fact] public void DefaultPropertyAsNull() { // Arrange & Act - DeprecatedRevisionsType revision = new(); + RevisionRecord revision = new(); // Assert Assert.Null(revision.Date); @@ -30,7 +30,7 @@ public void DefaultPropertyAsNull() public void InitializeWithNullRecordThrows() { // Arrange & Act - DeprecatedRevisionsType revision = new(); + RevisionRecord revision = new(); // Assert Assert.Throws("record", () => revision.Initialize(record: null)); @@ -50,7 +50,7 @@ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess() new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test"))); // Act - DeprecatedRevisionsType revision = new(); + RevisionRecord revision = new(); revision.Initialize(record); // Assert @@ -67,20 +67,32 @@ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess() Assert.Equal(new DateTime(2021, 10, 24), revision.RemovalDate); } [Fact] - public void ThrowsOnWrongKind() + public void WorksForAllKinds() { // Arrange - IEdmRecordExpression record = new EdmRecordExpression( + IEdmRecordExpression record1 = new EdmRecordExpression( new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2021, 8, 24))), new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2021, 10, 24))), new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(addedValue)), new EdmPropertyConstructor("Description", new EdmStringConstant("The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API.")), new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test"))); + IEdmRecordExpression record2 = new EdmRecordExpression( + new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2023, 3, 2))), + new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2023, 05, 30))), + new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(deprecatedValue)), + new EdmPropertyConstructor("Description", new EdmStringConstant("Private preview test.")), + new EdmPropertyConstructor("Version", new EdmStringConstant("2023-03/test"))); + // Act - DeprecatedRevisionsType revision = new(); + RevisionRecord revision1 = new(); + revision1.Initialize(record1); + + RevisionRecord revision2 = new(); + revision2.Initialize(record2); // Assert - Assert.Throws(() => revision.Initialize(record)); + Assert.Equal(RevisionKind.Added, revision1.Kind); + Assert.Equal(RevisionKind.Deprecated, revision2.Kind); } } \ No newline at end of file