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

Support optional facets on type definitions #2791

Open
wants to merge 1 commit into
base: release-7.x
Choose a base branch
from

Conversation

gathogojr
Copy link
Contributor

@gathogojr gathogojr commented Nov 14, 2023

Issues

This pull request fixes #2246.

Description

This pull request is a follow up to #2779. It implements support for facets that appear on type definitions. For example,

<TypeDefinition Name="SimpleIdentifier" UnderlyingType="Edm.String" MaxLength="128">
  <Annotation Term="Core.Description" String="A [simple identifier](https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_SimpleIdentifier)" />
  <Annotation Term="Validation.Pattern" String="^[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}$" />
</TypeDefinition>

Notes:

  • Currently, when a string property doesn't specify a Unicode facet, a default value of true is implied. For the same reason, when serializing an string property, we currently don't write the Unicode facet if the value is true or null. However, when it comes to a Unicode facet specified on a type definition, we should be explicit when serializing the type definition, i.e., write the Unicode facet if the value is true. This is because elements that use a type definition MUST NOT re-specify any facet specified on the type definition. Reading and writing the facet as explicitly specified makes it easy to validate this restriction.
  • For same reasoning as above, we explicitly write the spatial reference system identifier (SRID) value for Geometry and Geography properties where their default values (0 and 4326 respectively) are explicitly specified on a type definition.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@gathogojr gathogojr force-pushed the fix/support-optional-facets-on-type-definitions branch 3 times, most recently from 89a2fe4 to 48c7ca7 Compare November 20, 2023 05:36
Copy link
Contributor

@habbes habbes left a comment

Choose a reason for hiding this comment

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

Should this feature also be supported in CSDL JSON?

@gathogojr gathogojr force-pushed the fix/support-optional-facets-on-type-definitions branch from 48c7ca7 to ca7122d Compare November 20, 2023 08:35
@gathogojr
Copy link
Contributor Author

Should this feature also be supported in CSDL JSON?

@habbes Good catch. Made the relevant changes to ensure the facets get serialized for CSDL/JSON. The CSDL parser currently doesn't support deserializing CSDL/JSON.

@gathogojr gathogojr force-pushed the fix/support-optional-facets-on-type-definitions branch from ca7122d to cd4b9ca Compare November 20, 2023 11:09
habbes
habbes previously approved these changes Nov 20, 2023
@@ -12,16 +12,48 @@ namespace Microsoft.OData.Edm.Csdl.Parsing.Ast
internal class CsdlTypeDefinition : CsdlNamedElement
{
private readonly string underlyingTypeName;
private readonly int? maxLength;
Copy link
Member

Choose a reason for hiding this comment

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

I can't understand it, in my opinion, the facts should go to its underly type of the type definition, right?
For example, maxLength is for the underlying "Edm.String" primitive type.

@@ -754,6 +754,18 @@ internal override void WriteTypeDefinitionElementHeader(IEdmTypeDefinition typeD
this.xmlWriter.WriteStartElement(CsdlConstants.Element_TypeDefinition);
this.WriteRequiredAttribute(CsdlConstants.Attribute_Name, typeDefinition.Name, EdmValueWriter.StringAsXml);
this.WriteRequiredAttribute(CsdlConstants.Attribute_UnderlyingType, typeDefinition.UnderlyingType, this.TypeDefinitionAsXml);

if (typeDefinition is IEdmFacetedTypeDefinition facetedTypeDefinition)
Copy link
Member

Choose a reason for hiding this comment

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

we should use the underlyingType to write the facts.


if (typeDefinition is IEdmFacetedTypeDefinition facetedTypeDefinition)
{
this.jsonWriter.WriteOptionalProperty("$MaxLength", facetedTypeDefinition.MaxLength);
Copy link
Member

Choose a reason for hiding this comment

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

we should use the underlyingType to write the facts

@@ -14,7 +14,7 @@ namespace Microsoft.OData.Edm.Csdl.CsdlSemantics
/// <summary>
/// Provides semantics for CsdlTypeDefinition.
/// </summary>
internal class CsdlSemanticsTypeDefinitionDefinition : CsdlSemanticsTypeDefinition, IEdmTypeDefinition, IEdmFullNamedElement
internal class CsdlSemanticsTypeDefinitionDefinition : CsdlSemanticsTypeDefinition, IEdmTypeDefinition, IEdmFullNamedElement, IEdmFacetedTypeDefinition
Copy link
Contributor

Choose a reason for hiding this comment

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

Since IEdmFacetedTypeDefinition implements IEdmTypeDefinition, do we need IEdmTypeDefinition here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KenitoInc I'd be more comfortable leaving it as is since there's no harm. If we merge IEdmFacetedTypeDefinition into IEdmTypeDefinition in the next major release, the action will be seamless.

@gathogojr gathogojr force-pushed the fix/support-optional-facets-on-type-definitions branch from cd4b9ca to 35643dd Compare December 1, 2023 11:32
@gathogojr gathogojr force-pushed the fix/support-optional-facets-on-type-definitions branch from 35643dd to 1f59c49 Compare January 26, 2024 11:09

This PR has 303 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Large
Size       : +297 -6
Percentile : 70.3%

Total files changed: 14

Change summary by file extension:
.cs : +296 -5
.xml : +1 -1

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

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

Successfully merging this pull request may close these issues.

Microsoft.OData.Edm 7.9.4 can't parse standard core vocabulary
4 participants