Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1817: support key alias #3145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

xuzhg
Copy link
Member

@xuzhg xuzhg commented Dec 6, 2024

Fixes #1817: support key alias
Introduce the IEdmPropertyRef interface
Use default interface method for IEdmEntityType avoid breaking changes
This change focus on Edm lib, if it's ready and will move to OData.Core.

@xuzhg
Copy link
Member Author

xuzhg commented Dec 6, 2024

I'd like to move the key alias feature forward.
It's not a duplicated of PR: #2411.
It's a different implementation.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 23 changed files in this pull request and generated 1 suggestion.

Files not reviewed (15)
  • src/Microsoft.OData.Edm/Microsoft.OData.Edm.csproj: Language not supported
  • src/Microsoft.OData.Edm/Microsoft.OData.Edm.txt: Language not supported
  • src/Microsoft.OData.Edm/PublicAPI/net8.0/PublicAPI.Unshipped.txt: Language not supported
  • src/Microsoft.OData.Edm/Csdl/Serialization/EdmModelCsdlSchemaWriter.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Parsing/SchemaJsonParser.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Semantics/BadElements/UnresolvedPropertyRef.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Serialization/EdmModelCsdlSchemaXmlWriter.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Serialization/EdmModelCsdlSerializationVisitor.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Microsoft.OData.Edm.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Parsing/CsdlDocumentParser.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Validation/EdmErrorCode.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Csdl/Parsing/Ast/CsdlPropertyReference.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Parameterized.Microsoft.OData.Edm.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Schema/Interfaces/IEdmEntityType.cs: Evaluated as low risk
  • src/Microsoft.OData.Edm/Schema/EdmEntityType.cs: Evaluated as low risk
Comments skipped due to low confidence (1)

src/Microsoft.OData.Edm/Schema/Interfaces/IEdmPropertyRef.cs:29

  • [nitpick] The description for PropertyAlias could be more detailed to explain its purpose and usage.
string PropertyAlias { get; }

}

IEdmProperty edmProperty = FindPropertyOnType(edmStructuredType, segment);
if (i == segment.Length - 1)
Copy link
Preview

Copilot AI Dec 6, 2024

Choose a reason for hiding this comment

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

The condition should be 'if (i == segments.Length - 1)' to correctly identify the last segment in the path.

Suggested change
if (i == segment.Length - 1)
if (i == segments.Length - 1)

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Introduce the IEdmPropertyRef interface
Use default interface method for IEdmEntityType avoid breaking changes
This change focus on Edm lib, if it's ready and will move to OData.Core.
@xuzhg xuzhg force-pushed the issue1817_SupportKeyAlias branch from 943889a to 8540bc5 Compare December 6, 2024 19:26
@@ -0,0 +1,30 @@
//---------------------------------------------------------------------
// <copyright file="UnresolvedProperty.cs" company="Microsoft">
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be UnresolvedPropertyRef.cs instead of UnresolvedProperty.cs

Suggested change
// <copyright file="UnresolvedProperty.cs" company="Microsoft">
// <copyright file="UnresolvedPropertyRef.cs" company="Microsoft">

@@ -650,21 +650,37 @@ internal static CsdlKey ParseCsdlKey(string name, JsonElement keyArray, JsonPars
Debug.Assert(keyArray.ValueKind == JsonValueKind.Array);
Debug.Assert(name == "$Key", "The name should be $Key.");
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the $Key is in lowercase: $key

foreach (CsdlPropertyReference keyProperty in this.entity.Key.Properties)
{
IEdmStructuralProperty structuralProperty = this.FindProperty(keyProperty.PropertyName) as IEdmStructuralProperty;
IEdmStructuralProperty structuralProperty = FindKeyProperty(keyProperty.PropertyName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IEdmStructuralProperty structuralProperty = FindKeyProperty(keyProperty.PropertyName);
IEdmStructuralProperty structuralProperty = this.FindKeyProperty(keyProperty.PropertyName);

Or define FindKeyProperty as static method

@@ -2155,6 +2157,200 @@ public void CanWriteUrlEscapeFunction()
}");
}

[Fact]
public void CanWriteEntityType_WithSimpleKey_WithOrWithoutAlias()
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add equivalent Async tests for these Sync tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support OData key alias
2 participants