Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Operation;
using Microsoft.OpenApi.OData.PathItem;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
using Microsoft.OpenApi.OData.Vocabulary.Core;

namespace Microsoft.OpenApi.OData.Edm
{
Expand Down Expand Up @@ -171,5 +173,12 @@ private IEnumerable<ODataPath> LoadAllODataPaths()
yield return path;
}
}
internal IEnumerable<DeprecatedRevisionsType> GetDeprecationInformations(IEdmVocabularyAnnotatable annotable)
{
return annotable == null ?
Enumerable.Empty<DeprecatedRevisionsType>() :
(Model?.GetCollection<DeprecatedRevisionsType>(annotable, "Org.OData.Core.V1.Revisions") ??
Enumerable.Empty<DeprecatedRevisionsType>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment the codes, tab -> 4 whitespaces

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you can implement the default "GetAnnotables()" at the base class to return an empty Enumerable. Only override the method in the class that should be overridden?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I didn't make it virtual is because I want the compiler to error out in case we forgot a segment type instead of silently pass. This is going to come handy as we coordinate with PRs that add other segment types. But it could mean a breaking change for people whom inherited from the OData segment class, so I'm willing to compromise on this one. What do you think?

{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
}
}
9 changes: 8 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/Edm/ODataKeySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

namespace Microsoft.OpenApi.OData.Edm
Expand Down Expand Up @@ -63,7 +64,13 @@ public override string Identifier
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
{
Utils.CheckArgumentNull(settings, nameof(settings));

Expand Down
10 changes: 9 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/Edm/ODataMetadataSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$metadata";
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$metadata";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationProperty.Name;
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return new IEdmVocabularyAnnotatable[] { NavigationProperty, EntityType }.Union(EntityType.FindAllBaseTypes());
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationProperty.Name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationSource.Name;
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return new IEdmVocabularyAnnotatable[] { NavigationSource as IEdmVocabularyAnnotatable, EntityType }.Union(EntityType.FindAllBaseTypes());
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => NavigationSource.Name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return new IEdmVocabularyAnnotatable[] { OperationImport };
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
{
Utils.CheckArgumentNull(settings, nameof(settings));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

namespace Microsoft.OpenApi.OData.Edm
Expand Down Expand Up @@ -169,5 +170,11 @@ private string ActionName(IEdmAction action, OpenApiConvertSettings settings)
return action.FullName();
}
}
}

/// <inheritdoc />
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return new IEdmVocabularyAnnotatable[] { Operation };
}
}
}
10 changes: 9 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/Edm/ODataRefSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$ref";
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$ref";
}
}
12 changes: 11 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/Edm/ODataSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.OpenApiExtensions;

namespace Microsoft.OpenApi.OData.Edm
{
Expand Down Expand Up @@ -121,5 +122,14 @@ public string GetPathHash(OpenApiConvertSettings settings, ODataPath path = defa
/// <param name="parameters">The existing parameters.</param>
/// <returns>The path item name.</returns>
public abstract string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters);

/// <summary>
/// Provides any deprecation information for the segment.
/// </summary>
public OpenApiDeprecationExtension Deprecation { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation looks for the ODataPath, not a certain Segment in the Path, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each segment can have deprecation information, which means a path can have multiple deprecations. Then the path will take the uppermost (shortest path) deprecation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a good example of that is me/mailFolders/{id}/messages/{id}/attachments where in theory:

  • the user type (or a parent type) could be deprecated
  • the me singleton could be depracated
  • the mailFolder (or a parent type) could be deprecated
  • the mailFolders navigation property could be deprecated
  • ...

Assuming we have deprecation for all of those, the deprecation for the path that will be used, is the one from user, if user is not deprecated, the one from me, if not me, mailfolder, etc....

/// <summary>
/// Returns the list of <see cref="IEdmVocabularyAnnotatable"/> this segment refers to.
/// </summary>
public abstract IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$value";
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$value";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => _streamPropertyName;
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => _streamPropertyName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;

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

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => EntityType.FullTypeName();
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
{
return new IEdmVocabularyAnnotatable[] { EntityType };
}

/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => EntityType.FullTypeName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ public static string GetString(this IEdmRecordExpression record, string property
null;
}

/// <summary>
/// Get the DateTime value from the record using the given property name.
/// </summary>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The DateTime value or null.</returns>
public static DateTime? GetDateTime(this IEdmRecordExpression record, string propertyName)
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));

return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
property.Value is IEdmDateConstantExpression value) ?
value.Value :
null;
}

/// <summary>
/// Get the Enum value from the record using the given property name.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public string PathPrefix
/// </summary>
public bool RequireDerivedTypesConstraintForODataTypeCastSegments { get; set; } = true;

/// <summary>
/// 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.
/// </summary>
public bool EnableDeprecationInformation { get; set; } = true;

internal OpenApiConvertSettings Clone()
{
var newSettings = new OpenApiConvertSettings
Expand Down Expand Up @@ -237,6 +242,7 @@ internal OpenApiConvertSettings Clone()
AddSingleQuotesForStringParameters = this.AddSingleQuotesForStringParameters,
EnableODataTypeCast = this.EnableODataTypeCast,
RequireDerivedTypesConstraintForODataTypeCastSegments = this.RequireDerivedTypesConstraintForODataTypeCastSegments,
EnableDeprecationInformation = this.EnableDeprecationInformation,
};

return newSettings;
Expand Down
Loading