Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export interface PatientDocument {

// @public
export interface PatientInfo {
birthDate?: string;
birthDate?: Date;
clinicalInfo?: Resource[];
sex?: PatientInfoSex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ export interface PatientInfo {
/** The patient's sex. */
sex?: PatientInfoSex;
/** The patient's date of birth. */
birthDate?: string;
birthDate?: Date;
/** Known clinical information for the patient, structured. */
clinicalInfo?: Resource[];
}

export function patientInfoSerializer(item: PatientInfo): any {
return {
sex: item["sex"],
birthDate: item["birthDate"],
birthDate: !item["birthDate"]
? item["birthDate"]
: item["birthDate"].toISOString().split("T")[0],
clinicalInfo: !item["clinicalInfo"]
? item["clinicalInfo"]
: resourceArraySerializer(item["clinicalInfo"]),
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-ts/src/modular/emitSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ function getParameterValue(
switch (value.kind) {
case "string": {
switch (value.type.kind) {
case "plainDate":
case "utcDateTime":
retValue = `new Date("${value.value}")`;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,9 @@ export function serializeRequestValue(
? `!${clientValue}? ${clientValue}: `
: "";
switch (type.kind) {
case "plainDate":
// plainDate always uses ISO8601 format (YYYY-MM-DD)
return `${nullOrUndefinedPrefix}${clientValue}.toISOString().split('T')[0]`;
case "utcDateTime":
switch (type.encode ?? format) {
case "rfc7231":
Expand Down Expand Up @@ -1849,6 +1852,9 @@ export function deserializeResponseValue(
? `!${restValue}? ${restValue}: `
: "";
switch (type.kind) {
case "plainDate":
// plainDate deserializes from YYYY-MM-DD string to Date
return `${nullOrUndefinedPrefix} new Date(${restValue})`;
case "utcDateTime":
return `${nullOrUndefinedPrefix} new Date(${type.encode === "unixTimestamp" ? `${restValue} * 1000` : restValue})`;
case "array": {
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-ts/src/modular/helpers/typeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const NumericTypeKinds = [
"decimal128"
];

const DateTimeTypeKinds = ["plainDate", "plainTime"];
const DateTimeTypeKinds = ["plainTime"];

// This may be a good candidate to move to TCGC
export function isNumericTypeKind(kind: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function isSpecialUnionVariant(

if (
t.kind === "utcDateTime" ||
t.kind === "plainDate" ||
t.kind === "bytes" ||
(t.kind === "model" &&
t.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function getTypeExpression(
}
return "number";
case "endpoint":
case "plainDate":
case "plainTime":
case "string":
case "url":
Expand Down Expand Up @@ -103,6 +102,7 @@ export function getTypeExpression(
case "union":
return getUnionExpression(context, type, options);
case "utcDateTime":
case "plainDate":
return "Date";

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export declare interface PlainDateOperations {
}

export declare interface PlainDateProperty {
property?: string;
property?: Date;
}

export declare interface PlainDatePutAllOptionalParams extends OperationOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("OptionalProperties Modular Client", () => {
});

it("should handle optional plainDate", async () => {
const testValue = "2022-12-12";
const testValue = new Date("2022-12-12");
const result = await client.plainDate.getAll();
assert.deepEqual(result.property, testValue);
const result2 = await client.plainDate.getDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export declare interface PlainDateOperations {
}

export declare interface PlainDateProperty {
property?: string;
property?: Date;
}

export declare interface PlainDatePutAllOptionalParams extends OperationOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("OptionalProperties Modular Client", () => {
});

it("should handle optional plainDate", async () => {
const testValue = "2022-12-12";
const testValue = new Date("2022-12-12");
const result = await client.plainDate.getAll();
assert.deepEqual(result.property, testValue);
const result2 = await client.plainDate.getDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ op read(@body body: Foo): { @body body: Foo };
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/** model interface Foo */
export interface Foo {
prop1: string;
prop1: Date;
prop2: string;
prop3: Date;
prop4: string;
Expand All @@ -423,7 +423,7 @@ export interface Foo {
```ts models function fooSerializer
export function fooSerializer(item: Foo): any {
return {
prop1: item["prop1"],
prop1: item["prop1"].toISOString().split('T')[0],
prop2: item["prop2"],
prop3: item["prop3"].toISOString(),
prop4: item["prop4"],
Expand All @@ -436,7 +436,7 @@ export function fooSerializer(item: Foo): any {
```ts models function fooDeserializer
export function fooDeserializer(item: any): Foo {
return {
prop1: item["prop1"],
prop1: new Date(item["prop1"]),
prop2: item["prop2"],
prop3: new Date(item["prop3"]),
prop4: item["prop4"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function read(): Promise<void> {
stringLiteral: "foo",
booleanLiteral: true,
numberLiteral: 12,
plainDateProp: "2022-12-12",
plainDateProp: new Date("2022-12-12"),
plainTimeProp: "13:06:12",
utcDateTimeProp: new Date("2022-08-26T18:38:00Z"),
offsetDateTimeProp: "2022-08-26T18:38:00Z",
Expand Down
Loading