Skip to content

Commit

Permalink
[tcgc] unify datetime casing by renaming interface types (Azure#1067)
Browse files Browse the repository at this point in the history
fixes Azure#799

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
  • Loading branch information
2 people authored and markcowl committed Jun 26, 2024
1 parent 8e6e6e6 commit a1a4bad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/rename_datetime_type-2024-5-24-14-52-19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

Unify casing of datetime spelling to `DateTime`. Change interface names to `SdkDateTimeType`, `SdkUtcDateTimeType`, and `SdkOffsetDateTimeType`
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/doc/types.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ model SdkBuiltInType extends SdkType {
* @property encode: How to encode the datetime and represent to users
* @property wireType: What type we end up sending over the wire for a datetime. Can be a string or an int type.
*/
model SdkDatetimeType extends SdkType {
model SdkDateTimeType extends SdkType {
kind: "datetime";
encode: DateTimeKnownEncoding;
wireType: SdkType;
Expand Down
31 changes: 23 additions & 8 deletions packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface SdkTypeBase {

export type SdkType =
| SdkBuiltInType
| SdkDatetimeType
| SdkDateTimeType
| SdkDurationType
| SdkArrayType
| SdkTupleType
Expand Down Expand Up @@ -197,26 +197,41 @@ export function isSdkFloatKind(kind: string): kind is keyof typeof SdkFloatKinds
return kind in SdkFloatKindsEnum;
}

const SdkDatetimeEncodingsConst = ["rfc3339", "rfc7231", "unixTimestamp"] as const;
const SdkDateTimeEncodingsConst = ["rfc3339", "rfc7231", "unixTimestamp"] as const;

export function isSdkDatetimeEncodings(encoding: string): encoding is DateTimeKnownEncoding {
return SdkDatetimeEncodingsConst.includes(encoding as DateTimeKnownEncoding);
export function isSdkDateTimeEncodings(encoding: string): encoding is DateTimeKnownEncoding {
return SdkDateTimeEncodingsConst.includes(encoding as DateTimeKnownEncoding);
}

interface SdkDatetimeTypeBase extends SdkTypeBase {
interface SdkDateTimeTypeBase extends SdkTypeBase {
encode: DateTimeKnownEncoding;
wireType: SdkBuiltInType;
}

interface SdkUtcDatetimeType extends SdkDatetimeTypeBase {
interface SdkUtcDateTimeType extends SdkDateTimeTypeBase {
kind: "utcDateTime";
}

interface SdkOffsetDatetimeType extends SdkDatetimeTypeBase {
interface SdkOffsetDateTimeType extends SdkDateTimeTypeBase {
kind: "offsetDateTime";
}

export type SdkDatetimeType = SdkUtcDatetimeType | SdkOffsetDatetimeType;
export type SdkDateTimeType = SdkUtcDateTimeType | SdkOffsetDateTimeType;

/**
* @deprecated: Use SdkDateTimeType instead.
*/
export type SdkDatetimeType = SdkDateTimeType;

/**
* @deprecated: Use SdkUtcDateTimeType instead.
*/
export type SdkUtcDatetimeType = SdkUtcDateTimeType;

/**
* @deprecated Use SdkOffsetDateTimeType instead.
*/
export type SdkOffsetDatetimeType = SdkOffsetDateTimeType;

export interface SdkDurationType extends SdkTypeBase {
kind: "duration";
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
SdkConstantType,
SdkCredentialParameter,
SdkCredentialType,
SdkDatetimeType,
SdkDateTimeType,
SdkDictionaryType,
SdkDurationType,
SdkEnumType,
Expand Down Expand Up @@ -840,7 +840,7 @@ export function getClientTypeWithDiagnostics(
...getSdkTypeBaseHelper(context, type, type.name),
encode: "rfc3339",
wireType: { ...getSdkTypeBaseHelper(context, type, "string"), encode: "string" },
} as SdkDatetimeType;
} as SdkDateTimeType;
break;
}
if (type.name === "duration") {
Expand Down

0 comments on commit a1a4bad

Please sign in to comment.