Skip to content

Commit

Permalink
[tcgc] remove primitive type consolidation (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Feb 6, 2024
1 parent da4c38e commit 3997779
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-steaks-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/typespec-client-generator-core": minor
---

tcgc will return the raw tsp types to emitters, instead of doing more conversion
40 changes: 27 additions & 13 deletions packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,41 @@ export interface SdkBuiltInType extends SdkTypeBase {
encode: string;
}

export type SdkBuiltInKinds =
| "bytes"
| "boolean"
| "date"
| "time"
| "any"
type SdkIntKinds =
| "numeric"
| "integer"
| "safeint"
| "int8"
| "int16"
| "int32"
| "int64"
| "float32"
| "float64"
| "decimal"
| "decimal128"
| "uint8"
| "uint16"
| "uint32"
| "uint64";

type SdkFloatKinds = "float" | "float32" | "float64" | "decimal" | "decimal128";

type SdkStringKinds =
| "string"
| "password"
| "guid"
| "url"
| "uuid"
| "password"
| "etag"
| "armId"
| "ipAddress"
| "azureLocation"
| "etag";
| "azureLocation";

export type SdkBuiltInKinds =
| "bytes"
| "boolean"
| "plainDate"
| "plainTime"
| "any"
| SdkIntKinds
| SdkFloatKinds
| SdkStringKinds;

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

Expand Down
16 changes: 5 additions & 11 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,25 @@ function getScalarKind(scalar: Scalar): SdkBuiltInKinds {
case "int8":
case "int16":
case "int32":
case "int64":
case "uint8":
case "uint16":
case "uint32":
case "uint64":
case "numeric":
case "integer":
return "int32";
case "safeint":
case "uint64":
case "int64":
return "int64";
case "plainDate":
return "date";
case "plainTime":
return "time";
case "float":
return "float32";
case "decimal128":
return "decimal128";
case "bytes":
case "float":
case "float32":
case "float64":
case "boolean":
case "string":
case "url":
case "decimal":
case "plainDate":
case "plainTime":
return scalar.name;
default:
throw Error(`Unknown scalar kind ${scalar.name}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe("typespec-client-generator-core: types", () => {
);
const sdkType = getSdkTypeHelper(runner);
strictEqual(sdkType.kind, "duration");
strictEqual(sdkType.wireType.kind, "float32");
strictEqual(sdkType.wireType.kind, "float");
strictEqual(sdkType.encode, "seconds");
});

Expand Down

0 comments on commit 3997779

Please sign in to comment.