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 encode for modular #2006

Merged
merged 19 commits into from
Sep 11, 2023
Merged

Conversation

qiaozha
Copy link
Member

@qiaozha qiaozha commented Sep 6, 2023

add support for encode for datetime, duration, bytes in Modular.

for datetime, Modular layer will always be a Date type, but RLC layer will be different.

  1. In the case "rfc7231" or if the default in header, RLC layer will be a utc datetime string.
    serialize: someDate.toUTCString()
    deserialize: Date(someUTCString)
  2. In the case of "unixTimestamp", RLC layer will be a number.
    serialize: someDate.getTime()
    deserialize: Date(someUnixTimestamp)
  3. In the case of "rfc3339":or default not in header, RLC layer will be a ISO datetime string.
    serialize: someDate.toISOString()
    deserialize: Date(someISOString)

for duration

  1. In the case of format "seconds", both Modular and RLC layer will use number.
  2. In the case of "ISO8601" or default, both Modular and RLC layer will use string.

for bytes:

  1. Modular layer will be Uint8Array and RLC layer will be string no matter what format is using
    serialize: uint8ArrayToString(value, format)
    deserialize: stringToUint8Array(value, format)

fixes #2007

@qiaozha qiaozha marked this pull request as ready for review September 7, 2023 06:30
name: p["name"],
values: p["values"],
})),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you point to me where is the fix code?

@@ -63,8 +63,7 @@ export function _publishCloudEventSend(
? uint8ArrayToString(event["dataBase64"], "base64")
: undefined,
type: event["type"],
time:
event["time"] !== undefined ? new Date(event["time"]) : undefined,
time: event["time"]?.toISOString(),
Copy link
Contributor

@MaryGao MaryGao Sep 8, 2023

Choose a reason for hiding this comment

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

I notice the typespec type here is utcDateTime but we generate to toISOString

https://github.com/Azure/autorest.typescript/blob/1235e0ba4762ac1171f5777b50eafb1b7e43a8d0/packages/typespec-test/test/eventgrid_modular/spec/main.tsp#L64-L65C24

Not sure it is possible to add some UTs to cover typespec type to modular type:

/**
 * A date on a calendar without a time zone, e.g. "April 10th"
 */
scalar plainDate;

/**
 * A time on a clock without a time zone, e.g. "3:00 am"
 */
scalar plainTime;

/**
 * An instant in coordinated universal time (UTC)"
 */
scalar utcDateTime;

/**
 * A date and time in a particular time zone, e.g. "April 10th at 3:00am in PST"
 */
scalar offsetDateTime;

Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect typespec compiler does not provide any format info to these types, but let me check.

Copy link
Member Author

Choose a reason for hiding this comment

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

typescript date.toUTCString() is "Fri, 08 Sep 2023 08:50:03 GMT" and date.toISOString() is "2023-09-08T08:42:49.439Z"
therefore use toISOString for utcDateTime makes more sense. and toUTCString for offsetDateTime makes more sense to me.

Copy link
Contributor

@MaryGao MaryGao Sep 11, 2023

Choose a reason for hiding this comment

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

Yeah, it makes sense to me also. Just checking with Tim here microsoft/typespec#1899 (comment)

Copy link
Contributor

@MaryGao MaryGao Sep 12, 2023

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

They are not the same
image

return `"${param.restApiName}": options?.${param.clientName} !== undefined ? ${collectionInfo}(options?.${param.clientName}${additionalParam}): undefined`;
if (!param.optional) {
return `"${param.restApiName}": ${collectionInfo}(${serializeRequestValue(
param.type,
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 the change makes sense for me.

param.type.type === "datetime"
? "headerDefault"
: param.format
)}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

It should be here fixing the options.filters

Copy link
Contributor

@MaryGao MaryGao left a comment

Choose a reason for hiding this comment

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

LGTM and just left small comments for checking and one ut.

@qiaozha qiaozha merged commit 34b32bd into Azure:main Sep 11, 2023
28 checks passed
@qiaozha qiaozha deleted the add-encode-test-case-for-modular branch September 11, 2023 09:23
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.

[JS] Mismatch Type for 'file' Property
2 participants