Migrated from Azure/autorest.go#2026
Description
The example test generator produces uncompilable Go code for utcDateTime properties encoded as rfc7231. The generated value is wrapped in strconv.ParseInt (the Unix-timestamp path) with an unquoted, non-numeric date string.
Repro
Generate armdomainservices (or any spec with an rfc7231-encoded datetime, e.g. ConfigDiagnostics.lastExecuted).
Actual (broken) output
LastExecuted: to.Ptr(func() time.Time { t, _ := strconv.ParseInt(05 May 2021 12:00:23 GMT, 10, 64); return time.Unix(t, 0).UTC()}()),
05 May 2021 12:00:23 GMT is unquoted -> does not compile
- Wrong parse path entirely (Unix timestamp instead of RFC1123 layout)
Expected output
LastExecuted: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC1123, "05 May 2021 12:00:23 GMT"); return t }()),
Root cause
PR Azure/autorest.go#1992 ("Use RFC7231 for tsp instead of RFC1123", commit d9189b9ac) changed the TypeSpec adapter to emit the RFC7231 TimeFormat value instead of RFC1123. It updated the consumers in servers.ts, operations.ts, models.ts, and type.ts, but missed packages/codegen.go/src/core/example.ts.
getTimeValue's formatMap only handled RFC1123 and RFC3339, so RFC7231 fell through to the else branch, which assumes a Unix timestamp:
const formatMap: Record<string, string> = {
PlainDate: helpers.plainDateFormat,
PlainTime: helpers.plainTimeFormat,
RFC1123: helpers.RFC1123Format,
RFC3339: helpers.RFC3339Format,
// RFC7231 missing
};
Fix
Add RFC7231: helpers.RFC1123Format to the map (mirrors the existing mapping in fake/servers.ts). Both share the Go time.RFC1123 layout.
Regression range
Introduced in Azure/autorest.go#1992 (emitter versions after 0.14.0).
Description
The example test generator produces uncompilable Go code for
utcDateTimeproperties encoded asrfc7231. The generated value is wrapped instrconv.ParseInt(the Unix-timestamp path) with an unquoted, non-numeric date string.Repro
Generate
armdomainservices(or any spec with anrfc7231-encoded datetime, e.g.ConfigDiagnostics.lastExecuted).Actual (broken) output
05 May 2021 12:00:23 GMTis unquoted -> does not compileExpected output
Root cause
PR Azure/autorest.go#1992 ("Use RFC7231 for tsp instead of RFC1123", commit
d9189b9ac) changed the TypeSpec adapter to emit theRFC7231TimeFormatvalue instead ofRFC1123. It updated the consumers inservers.ts,operations.ts,models.ts, andtype.ts, but missedpackages/codegen.go/src/core/example.ts.getTimeValue'sformatMaponly handledRFC1123andRFC3339, soRFC7231fell through to theelsebranch, which assumes a Unix timestamp:Fix
Add
RFC7231: helpers.RFC1123Formatto the map (mirrors the existing mapping infake/servers.ts). Both share the Gotime.RFC1123layout.Regression range
Introduced in Azure/autorest.go#1992 (emitter versions after 0.14.0).