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

feat: Respect precision for Odata V4 type Edm.DateTimeOffset #5361

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

KavithaSiva
Copy link
Contributor

Closes SAP/cloud-sdk-backlog#1261.

  • I know which base branch I chose for this PR, as the default branch is v3-main now, which is not for v4 development.
  • If my change will be merged into the main branch (for v4), I've updated (V4-Upgrade-Guide.md)[./V4-Upgrade-Guide.md] in case my change has any implications for users updating to SDK v4

@KavithaSiva KavithaSiva changed the title Support precision for Odata V4 type Edm.DateTimeOffset feat: Respect precision for Odata V4 type Edm.DateTimeOffset Jan 16, 2025
@KavithaSiva KavithaSiva marked this pull request as ready for review January 16, 2025 09:15
Comment on lines +2 to +4
'@sap-cloud-sdk/generator': minor
'@sap-cloud-sdk/odata-v4': minor
'@sap-cloud-sdk/odata-common': minor
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[q] Should I write major here? What is the correct heading for the PR then? feat needs a changeset with minor.

Copy link
Contributor

@deekshas8 deekshas8 left a comment

Choose a reason for hiding this comment

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

I will probably have another look, but left some initial comments already,

.changeset/funny-shrimps-visit.md Outdated Show resolved Hide resolved
const serialize = deSerializers[edmType as any]?.serialize;
// Check if the edmType is specifically Edm.DateTimeOffset as we can have precision, scale property defined
if (edmType === 'Edm.DateTimeOffset' && precision) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[req] If precision is 0 (which is a valid value) this will be falsy.
[q] Can we double check if it's only DateTimeOffset? or also valid for TimeStamp?

[q] Also, even if we just send precision without any checks, does it break anything? With JS it just ignores the extra params.

packages/odata-v4/src/de-serializers/converters.ts Outdated Show resolved Hide resolved
packages/odata-v4/src/de-serializers/converters.ts Outdated Show resolved Hide resolved
@@ -14,6 +14,7 @@ import {
serializeToTime,
deserializeDateToMoment
} from './converters';
import type { Moment } from 'moment';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not the correct way to import moment.

Copy link
Contributor Author

@KavithaSiva KavithaSiva Jan 27, 2025

Choose a reason for hiding this comment

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

I now removed the import as moment seems to be accessible without it in this file.

But, I don't understand how this works, and why we explicitly use import { Moment } from 'moment' in some places but use it directly in some.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's likely due to moment being a global namespace here (which allows using it without import statement). But for consistency we should still import it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you're using moment only for its type then use:

import type moment else import moment

@@ -603,7 +605,8 @@ export class TestEntity50PropApi<
DECIMAL_PROPERTY_2: fieldBuilder.buildEdmTypeField(
'DecimalProperty2',
'Edm.Decimal',
true
true,
9
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] What is the max allowed precision as per odata? Just want to make sure we're testing the correct values. If I remember cds allows only till 7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From OData spec:

For a decimal value: the maximum number of significant decimal digits of the property’s value; it MUST be
a positive integer.
For a temporal value (datetime-with-timezone-offset, duration, or time-of-day): the number of decimal
places allowed in the seconds portion of the value; it MUST be a non-negative integer between zero and
twelve.

Currently, precision values get generated for both temporal and decimal values.
But, I only use it for formatting DateTimeOffset fields.
I am okay with generating them for decimal fields as well, eventhough we don't use it, do you feel otherwise?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nicer if we generate it for types where we actually support it. otherwise it might be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would only update our test client code for cases where we actually support the behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was updated automatically now during generation, as we always add precision if it's available in the EDMX file.
Let me check, how to restrict this during generation only for temporal fields.

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.

3 participants