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
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,30 @@
/// <param name="propertyName">The property name.</param>
/// <returns>The Enum value or null.</returns>
public static T? GetEnum<T>(this IEdmRecordExpression record, string propertyName)
where T : struct
where T : struct, Enum
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));

return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
if (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal))
is IEdmPropertyConstructor property &&
property.Value is IEdmEnumMemberExpression value &&
value.EnumMembers != null &&
value.EnumMembers.Any() &&
Enum.TryParse(value.EnumMembers.First().Name, out T result)) ?
result :
null;
value.EnumMembers.Any())
{
long combinedValue = 0;
foreach (var enumMember in value.EnumMembers)
{
if (Enum.TryParse(enumMember.Name, out T enumValue))
{
combinedValue |= Convert.ToInt64(enumValue);
}
}

return (T)Enum.ToObject(typeof(T), combinedValue);
}

return null;
}

/// <summary>
Expand Down Expand Up @@ -175,7 +187,7 @@
}
}

return null;

Check warning on line 190 in src/Microsoft.OpenApi.OData.Reader/Edm/RecordExpressionExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Return an empty collection instead of null. (https://rules.sonarsource.com/csharp/RSPEC-1168)
}

/// <summary>
Expand All @@ -199,7 +211,7 @@
return items;
}

return null;

Check warning on line 214 in src/Microsoft.OpenApi.OData.Reader/Edm/RecordExpressionExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Return an empty collection instead of null. (https://rules.sonarsource.com/csharp/RSPEC-1168)
}

/// <summary>
Expand Down Expand Up @@ -229,7 +241,7 @@
return items;
}

return null;

Check warning on line 244 in src/Microsoft.OpenApi.OData.Reader/Edm/RecordExpressionExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Return an empty collection instead of null. (https://rules.sonarsource.com/csharp/RSPEC-1168)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.7.3</Version>
<Version>1.7.4</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
<PackageReleaseNotes>
- Fix regression in unique operation id generation at #462.
- Sync changes from https://github.com/microsoft/OpenAPI.NET.OData/pull/567 to V1 of the library
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public void AddUpdateOperation(OpenApiPathItem item)
if ((Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths && isUpdatable) ||
!Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths)
{
if (updateRestrictions != null && updateRestrictions.IsUpdateMethodPut)
if (updateRestrictions?.IsUpdateMethodPutAndPatch == true)
{
AddOperation(item, OperationType.Put);
AddOperation(item, OperationType.Patch);
}
else if (updateRestrictions?.IsUpdateMethodPut == true)
{
AddOperation(item, OperationType.Put);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ protected override void SetOperations(OpenApiPathItem item)
updateRestrictions ??= entityUpdateRestrictions;
if (updateRestrictions?.IsUpdatable ?? true)
{
if (updateRestrictions != null && updateRestrictions.IsUpdateMethodPut)
if (updateRestrictions?.IsUpdateMethodPutAndPatch == true)
{
AddOperation(item, OperationType.Put);
AddOperation(item, OperationType.Patch);
}
else if (updateRestrictions?.IsUpdateMethodPut == true)
{
AddOperation(item, OperationType.Put);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
?? navPropRestrictionType?.RestrictedProperties?.FirstOrDefault();

// Check whether the navigation property should be part of the path
if (EdmModelHelper.NavigationRestrictionsAllowsNavigability(navSourceRestrictionType, restriction) == false ||

Check warning on line 68 in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
EdmModelHelper.NavigationRestrictionsAllowsNavigability(navPropRestrictionType, restriction) == false)

Check warning on line 69 in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
return;
}
Expand Down Expand Up @@ -159,7 +159,7 @@
AddDeleteOperation(item, restriction);
}

private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction)

Check warning on line 162 in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
ReadRestrictionsType navPropReadRestriction = Context.Model.GetRecord<ReadRestrictionsType>(TargetPath, CapabilitiesConstants.ReadRestrictions);
navPropReadRestriction?.MergePropertiesIfNull(restriction?.ReadRestrictions);
Expand All @@ -178,7 +178,7 @@

if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
{
// TODO: $ref also supports Get ?

Check warning on line 181 in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
if (LastSegmentIsKeySegment)
{
if ((navPropReadRestriction?.ReadByKeyRestrictions?.IsReadable ?? true) &&
Expand All @@ -198,7 +198,7 @@
}
else
{
Debug.Assert(LastSegmentIsKeySegment == false);

Check warning on line 201 in src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
if ((navPropReadRestriction?.IsReadable ?? true) &&
(entityReadRestriction?.IsReadable ?? true))
{
Expand Down Expand Up @@ -243,17 +243,23 @@

private void AddUpdateOperation(OpenApiPathItem item, UpdateRestrictionsType updateRestrictionsType)
{
if (updateRestrictionsType == null || updateRestrictionsType.IsUpdatable)
{
if (updateRestrictionsType != null && updateRestrictionsType.IsUpdateMethodPut)
{
AddOperation(item, OperationType.Put);
}
else
{
AddOperation(item, OperationType.Patch);
}
}
if (updateRestrictionsType?.IsUpdatable ?? true)
{
if (updateRestrictionsType?.IsUpdateMethodPutAndPatch == true)
{
AddOperation(item, OperationType.Put);
AddOperation(item, OperationType.Patch);
}
else if (updateRestrictionsType?.IsUpdateMethodPut == true)
{
AddOperation(item, OperationType.Put);
}
else
{
AddOperation(item, OperationType.Patch);
}
}

}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;
Expand All @@ -14,17 +15,18 @@
/// <summary>
/// Enumerates HTTP methods that can be used to update entities
/// </summary>
[Flags]
internal enum HttpMethod

Check warning on line 19 in src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs

View workflow job for this annotation

GitHub Actions / Build

Rename this enumeration to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'. (https://rules.sonarsource.com/csharp/RSPEC-2342)
{
/// <summary>
/// The HTTP PATCH Method
/// </summary>
PATCH,
PATCH = 1,

/// <summary>
/// The HTTP PUT Method
/// </summary>
PUT
PUT = 2
}
/// <summary>
/// Complex Type: Org.OData.Capabilities.V1.UpdateRestrictionsType
Expand All @@ -46,10 +48,10 @@
/// <summary>
/// Gets the value indicating Entities can be inserted, updated, and deleted via a PATCH request with a delta payload.
/// </summary>
public bool? DeltaUpdateSupported { get; private set; }

public bool? DeltaUpdateSupported { get; private set; }
/// <summary>
/// Gets the value indicating the HTTP Method (PUT or PATCH) for updating an entity.
/// Gets the values indicating the HTTP Method (PUT and/or PATCH) for updating an entity.
/// If null, PATCH should be supported and PUT MAY be supported.
/// </summary>
public HttpMethod? UpdateMethod { get; private set; }
Expand Down Expand Up @@ -120,14 +122,20 @@
{
return NonUpdatableNavigationProperties != null ?
NonUpdatableNavigationProperties.Any(a => a == navigationPropertyPath) :
false;

Check warning on line 125 in src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
}

/// <summary>
/// Tests whether the update method for the entity has been explicitly specified as PUT
/// Tests whether the update method for the target has been explicitly specified as PUT
/// </summary>
public bool IsUpdateMethodPut => UpdateMethod.HasValue && UpdateMethod.Value == HttpMethod.PUT;

/// <summary>
/// Tests whether the update method for the target has been explicitly specified as PATCH and PUT
/// </summary>
public bool IsUpdateMethodPutAndPatch => UpdateMethod.HasValue &&
(UpdateMethod.Value & (HttpMethod.PUT | HttpMethod.PATCH)) == (HttpMethod.PUT | HttpMethod.PATCH);

/// <summary>
/// Lists the media types acceptable for the request content
/// </summary>
Expand Down Expand Up @@ -157,7 +165,7 @@
// DeltaUpdateSupported
DeltaUpdateSupported = record.GetBoolean("DeltaUpdateSupported");

// UpdateMethod
// UpdateMethod
UpdateMethod = record.GetEnum<HttpMethod>("UpdateMethod");

// FilterSegmentSupported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void CreatePathItemForNavigationPropertyAndUpdateMethodUpdateRestrictions
<PropertyValue Property=""UpdateRestrictions"" >
<Record>
<PropertyValue Property=""UpdateMethod"">
<EnumMember>Org.OData.Capabilities.V1.HttpMethod/PUT</EnumMember>
<EnumMember>Org.OData.Capabilities.V1.HttpMethod/PUT Org.OData.Capabilities.V1.HttpMethod/PATCH </EnumMember>
</PropertyValue>
<PropertyValue Property=""Updatable"" Bool=""{1}"" />
</Record>
Expand Down Expand Up @@ -488,21 +488,21 @@ public void CreatePathItemForNavigationPropertyAndUpdateMethodUpdateRestrictions
if (isContainment)
{
expected = updatable
? (new[] { OperationType.Get, OperationType.Put, OperationType.Delete })
: (new[] { OperationType.Get, OperationType.Delete });
? ([OperationType.Get, OperationType.Put, OperationType.Patch, OperationType.Delete])
: ([OperationType.Get, OperationType.Delete]);
}
else
{
expected = updatable
? (new[] { OperationType.Get, OperationType.Put })
: (new[] { OperationType.Get });
? ([OperationType.Get, OperationType.Put, OperationType.Patch,])
: ([OperationType.Get]);
}
}
else
{
expected = isContainment
? (new[] { OperationType.Get, OperationType.Patch, OperationType.Delete })
: (new[] { OperationType.Get });
? ([OperationType.Get, OperationType.Patch, OperationType.Delete])
: ([OperationType.Get]);

}

Expand Down
Loading