-
Notifications
You must be signed in to change notification settings - Fork 352
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
base: release-7.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
private readonly CsdlSemanticsSchema context; | ||
private readonly CsdlTypeDefinition typeDefinition; | ||
|
@@ -74,6 +74,16 @@ public override CsdlElement Element | |
get { return this.typeDefinition; } | ||
} | ||
|
||
public int? MaxLength => this.typeDefinition.MaxLength; | ||
|
||
public bool? IsUnicode => this.typeDefinition.IsUnicode; | ||
|
||
public int? Precision => this.typeDefinition.Precision; | ||
|
||
public int? Scale => this.typeDefinition.Scale; | ||
|
||
public int? Srid => this.typeDefinition.Srid; | ||
|
||
protected override IEnumerable<IEdmVocabularyAnnotation> ComputeInlineVocabularyAnnotations() | ||
{ | ||
return this.Model.WrapInlineVocabularyAnnotations(this, this.context); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1176,8 +1176,20 @@ internal override void WriteTypeDefinitionElementHeader(IEdmTypeDefinition typeD | |
// The type definition object MUST contain the member $Kind with a string value of TypeDefinition | ||
this.jsonWriter.WriteRequiredProperty("$Kind", CsdlConstants.Element_TypeDefinition); | ||
|
||
// The type definition object MUST contain he member $UnderlyingType. | ||
// The type definition object MUST contain the member $UnderlyingType. | ||
this.jsonWriter.WriteRequiredProperty("$UnderlyingType", typeDefinition.UnderlyingType, TypeDefinitionAsJson); | ||
|
||
if (typeDefinition is IEdmFacetedTypeDefinition facetedTypeDefinition) | ||
{ | ||
this.jsonWriter.WriteOptionalProperty("$MaxLength", facetedTypeDefinition.MaxLength); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use the |
||
this.jsonWriter.WriteOptionalProperty("$Unicode", facetedTypeDefinition.IsUnicode); | ||
this.jsonWriter.WriteOptionalProperty("$Precision", facetedTypeDefinition.Precision); | ||
this.jsonWriter.WriteOptionalProperty("$Scale", facetedTypeDefinition.Scale); | ||
if (facetedTypeDefinition.UnderlyingType.IsSpatial()) | ||
{ | ||
this.jsonWriter.WriteOptionalProperty("$SRID", facetedTypeDefinition.Srid, CsdlConstants.Default_UnspecifiedSrid); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use the |
||
{ | ||
this.WriteOptionalAttribute(CsdlConstants.Attribute_MaxLength, facetedTypeDefinition.MaxLength, EdmValueWriter.IntAsXml); | ||
this.WriteOptionalAttribute(CsdlConstants.Attribute_Unicode, facetedTypeDefinition.IsUnicode, EdmValueWriter.BooleanAsXml); | ||
this.WriteOptionalAttribute(CsdlConstants.Attribute_Precision, facetedTypeDefinition.Precision, EdmValueWriter.IntAsXml); | ||
this.WriteOptionalAttribute(CsdlConstants.Attribute_Scale, facetedTypeDefinition.Scale, EdmValueWriter.IntAsXml); | ||
if (facetedTypeDefinition.UnderlyingType.IsSpatial()) | ||
{ | ||
this.WriteOptionalAttribute(CsdlConstants.Attribute_Srid, facetedTypeDefinition.Srid, CsdlConstants.Default_UnspecifiedSrid, SridAsXml); | ||
} | ||
} | ||
} | ||
|
||
internal override void WriteEndElement() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="IEdmFacetedTypeDefinition.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
namespace Microsoft.OData.Edm | ||
{ | ||
/// <summary> | ||
/// Represents a definition of an EDM type definition that supports facets. | ||
/// </summary> | ||
public interface IEdmFacetedTypeDefinition : IEdmTypeDefinition | ||
{ | ||
/// <summary> | ||
/// Gets the optional maximum length type definition facet. | ||
/// </summary> | ||
int? MaxLength { get; } | ||
|
||
/// <summary> | ||
/// Gets the optional unicode type definition facet. | ||
/// </summary> | ||
bool? IsUnicode { get; } | ||
|
||
/// <summary> | ||
/// Gets the optional precision type definition facet. | ||
/// </summary> | ||
int? Precision { get; } | ||
|
||
/// <summary> | ||
/// Gets the optional scale type definition facet. | ||
/// </summary> | ||
int? Scale { get; } | ||
|
||
/// <summary> | ||
/// Gets the optional spatial reference identifier type definition facet. | ||
/// </summary> | ||
int? Srid { get; } | ||
} | ||
} |
There was a problem hiding this comment.
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.