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

Fix issue #2276: should use for @type for serializing record in CSDL JSON #2277

Merged
merged 1 commit into from
Jan 3, 2022

Conversation

xuzhg
Copy link
Member

@xuzhg xuzhg commented Dec 14, 2021

Issues

This pull request fixes #2276.

Description

7 Structural Property

A structural property is a property of a structured type that has one of the following types:

· Primitive type

· Complex type

· Enumeration type

· A collection of one of the above

A structural property MUST specify a unique name as well as a type.

The property’s name MUST be a simple identifier. It is used when referencing, serializing or deserializing the property. It MUST be unique within the set of structural and navigation properties of the declaring structured type, and MUST NOT match the name of any navigation property in any of its base types. If a structural property with the same name is defined in any of this type’s base types, then the property’s type MUST be a type derived from the type specified for the property of the base type and constrains this property to be of the specified subtype for instances of this structured type. The name MUST NOT match the name of any structural or navigation property of any of this type’s base types for OData 4.0 responses.

Names are case-sensitive, but service authors SHOULD NOT choose names that differ only in case.

Property Object

Structural properties are represented as members of the object representing a structured type. The member name is the property name, the member value is an object.

The property object MAY contain the member $Kind with a string value of Property. This member SHOULD be omitted to reduce document size.

It MAY contain the member $Type, $Collection, $Nullable, $MaxLength, $Unicode, $Precision, $Scale, $SRID, and $DefaultValue.

It also MAY contain annotations.

Example 15: complex type with two properties Dimension and Length

"Measurement": {

"$Kind": "ComplexType",

"Dimension": {

"$MaxLength": 50,

"$DefaultValue": "Unspecified"

},

"Length": {

"$Type": "Edm.Decimal",

"$Precision": 18,

"$Scale": 2

}

}

For the record:

14.4.12 Record
The record expression enables a new entity type or complex type instance to be constructed.

A record expression MAY specify the structured type of its result, which MUST be an entity type or complex type in scope. If not explicitly specified, the type is derived from the expression’s context.

A record expression contains zero or more property value expressions. For each single-valued structural or navigation property of the record expression’s type that is neither nullable nor specifies a default value a property value expression MUST be provided. The only exception is if the record expression is the value of an annotation for a term that has a base term whose type is structured and directly or indirectly inherits from the type of its base term. In this case, property values that already have been specified in the annotation for the base term or its base term etc. need not be specified again.

For collection-valued properties the absence of a property value expression is equivalent to specifying an empty collection as its value.

Record expressions are represented as objects with one member per property value expression. The member name is the property name, and the member value is the property value expression.

The type of a record expression is represented as the @type control information, see [OData‑JSON].

It MAY contain annotations for itself and its members. Annotations for record members are prefixed with the member name.

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.

@pull-request-quantifier-deprecated

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


Quantification details

Label      : Extra Small
Size       : +13 -10
Percentile : 9.2%

Total files changed: 4

Change summary by file extension:
.cs : +4 -4
.csproj : +9 -6

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 detetcted.
  • 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.

@xuzhg xuzhg requested review from habbes, mikepizzo and chrisspre and removed request for habbes December 14, 2021 22:32
Copy link
Member

@mikepizzo mikepizzo left a comment

Choose a reason for hiding this comment

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

What happens on read? Do we have tests that read both as $Type (for backward compat) and @type?

@xuzhg xuzhg requested a review from corranrogue9 December 16, 2021 21:57
@xuzhg
Copy link
Member Author

xuzhg commented Dec 17, 2021

What happens on read? Do we have tests that read both as $Type (for backward compat) and @type?

The reading has the correct process. See https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Edm/Csdl/Parsing/AnnotationJsonParser.cs#L431-L442

@xuzhg xuzhg merged commit e755cbf into master Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong type information for serializing records to CSDL JSON
2 participants