Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-python"
---

Fall back to wire type for unknown or unsupported encode
43 changes: 32 additions & 11 deletions packages/http-client-python/emitter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,39 @@ const sdkScalarKindToPythonKind: Record<string, string> = {
function emitBuiltInType(
type: SdkBuiltInType | SdkDurationType | SdkDateTimeType,
): Record<string, any> {
if (type.kind === "duration" && type.encode === "seconds") {
return getSimpleTypeResult({
type: sdkScalarKindToPythonKind[type.wireType.kind],
encode: type.encode,
});
}
if (type.encode === "unixTimestamp") {
return getSimpleTypeResult({
type: "unixtime",
encode: type.encode,
});
if (type.encode) {
if (type.kind === "duration") {
if (type.encode === "ISO8601") {
return getSimpleTypeResult({
type: type.kind,
encode: type.encode,
});
}
}
if (type.kind === "utcDateTime" || type.kind === "offsetDateTime") {
if (type.encode === "unixTimestamp") {
return getSimpleTypeResult({
type: "unixtime",
encode: type.encode,
});
}
if (type.encode === "rfc3339" || type.encode === "rfc7231") {
return getSimpleTypeResult({
type: type.kind,
encode: type.encode,
});
}
}

// fallback to wire type for unknown or unsupported encode
if ("wireType" in type && type.wireType !== undefined) {
return getSimpleTypeResult({
type: sdkScalarKindToPythonKind[type.wireType.kind] || type.wireType.kind,
encode: type.encode,
});
}
}

return getSimpleTypeResult({
type: sdkScalarKindToPythonKind[type.kind] || type.kind, // TODO: switch to kind
encode: type.encode,
Expand Down
Loading