From 778f5dcc07afaa971b1c4573530b590c9b63902d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 05:24:04 +0000 Subject: [PATCH 1/6] Initial plan From 39c538b4657bad9b07aa622ef8ff397972f976c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 05:25:33 +0000 Subject: [PATCH 2/6] Fix Go example generator for RFC7231 datetime values Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com> --- packages/typespec-go/src/codegen/core/example.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/typespec-go/src/codegen/core/example.ts b/packages/typespec-go/src/codegen/core/example.ts index df5acf6d12..0140b011f4 100644 --- a/packages/typespec-go/src/codegen/core/example.ts +++ b/packages/typespec-go/src/codegen/core/example.ts @@ -450,6 +450,7 @@ function getTimeValue(type: go.Time, value: any, imports?: ImportManager): strin PlainTime: helpers.plainTimeFormat, RFC1123: helpers.RFC1123Format, RFC3339: helpers.RFC3339Format, + RFC7231: helpers.RFC1123Format, }; if (type.format in formatMap) { From 4c6f4f990ceb375b5afe9a162231cb3781659506 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 05:29:07 +0000 Subject: [PATCH 3/6] Add chronus changelog for RFC7231 example fix Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com> --- .../fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md diff --git a/.chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md b/.chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md new file mode 100644 index 0000000000..26731ed981 --- /dev/null +++ b/.chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-go" +--- + +Fix the example generator emitting uncompilable Go for `utcDateTime` properties encoded as `rfc7231`. The `RFC7231` time format now maps to the Go `time.RFC1123` layout (`time.Parse`) instead of falling through to the Unix-timestamp `strconv.ParseInt` path. From a87ab32ef99648e6f20a734c2455f28912fb7fe1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 06:00:27 +0000 Subject: [PATCH 4/6] Add scenario test, chronus change via pnpm change add, bump version, update dev doc Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com> --- ...-go-rfc7231-datetime-2026-6-21-5-57-23.md} | 2 +- packages/typespec-go/docs/development.md | 3 +- packages/typespec-go/package.json | 2 +- .../rfc7231-datetime-sample.test.ts | 5 + .../scenarios/rfc7231-datetime-sample.md | 136 ++++++++++++++++++ 5 files changed, 145 insertions(+), 3 deletions(-) rename .chronus/changes/{fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md => copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md} (99%) create mode 100644 packages/typespec-go/test/unittest/scenario-suites/rfc7231-datetime-sample.test.ts create mode 100644 packages/typespec-go/test/unittest/scenarios/rfc7231-datetime-sample.md diff --git a/.chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md b/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md similarity index 99% rename from .chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md rename to .chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md index 26731ed981..aa97158211 100644 --- a/.chronus/changes/fix-go-example-rfc7231-datetime-2026-07-21-05-24-50.md +++ b/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-go" --- -Fix the example generator emitting uncompilable Go for `utcDateTime` properties encoded as `rfc7231`. The `RFC7231` time format now maps to the Go `time.RFC1123` layout (`time.Parse`) instead of falling through to the Unix-timestamp `strconv.ParseInt` path. +Fix the example generator emitting uncompilable Go for `utcDateTime` properties encoded as `rfc7231`. The `RFC7231` time format now maps to the Go `time.RFC1123` layout (`time.Parse`) instead of falling through to the Unix-timestamp `strconv.ParseInt` path. \ No newline at end of file diff --git a/packages/typespec-go/docs/development.md b/packages/typespec-go/docs/development.md index 561785ca94..b1c5b336cb 100644 --- a/packages/typespec-go/docs/development.md +++ b/packages/typespec-go/docs/development.md @@ -190,4 +190,5 @@ Before you do, make sure to: 1. Format your code (`pnpm format` from the repo root, or check with `pnpm format:check`). 2. Rebuild and regenerate everything so the committed fixtures reflect your change. -3. Add a changelog entry with [Chronus](https://github.com/microsoft/chronus) by running `npx chronus add` from the repo root and following the prompts. This creates a change file under `.chronus/changes/` that you should commit with your PR. +3. Bump the `version` field in `packages/typespec-go/package.json` (a patch bump for a bug fix, a minor bump for a new feature). +4. Add a changelog entry with [Chronus](https://github.com/microsoft/chronus) by running `pnpm change add` from the repo root and following the prompts. This creates a change file under `.chronus/changes/` that you should commit with your PR. diff --git a/packages/typespec-go/package.json b/packages/typespec-go/package.json index b11fc7dbd0..3ab3cea00f 100644 --- a/packages/typespec-go/package.json +++ b/packages/typespec-go/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-go", - "version": "0.15.0", + "version": "0.15.1", "author": "Microsoft Corporation", "description": "TypeSpec emitter for Go SDKs", "homepage": "https://azure.github.io/typespec-azure", diff --git a/packages/typespec-go/test/unittest/scenario-suites/rfc7231-datetime-sample.test.ts b/packages/typespec-go/test/unittest/scenario-suites/rfc7231-datetime-sample.test.ts new file mode 100644 index 0000000000..198d0a382a --- /dev/null +++ b/packages/typespec-go/test/unittest/scenario-suites/rfc7231-datetime-sample.test.ts @@ -0,0 +1,5 @@ +// Generated by `pnpm gen:scenario-suites`. Do not edit by hand. +import { resolvePath } from "@typespec/compiler"; +import { describeScenarioFile } from "../scenario-runner.js"; + +describeScenarioFile(resolvePath(import.meta.dirname, "../scenarios/rfc7231-datetime-sample.md")); diff --git a/packages/typespec-go/test/unittest/scenarios/rfc7231-datetime-sample.md b/packages/typespec-go/test/unittest/scenarios/rfc7231-datetime-sample.md new file mode 100644 index 0000000000..570a69c97f --- /dev/null +++ b/packages/typespec-go/test/unittest/scenarios/rfc7231-datetime-sample.md @@ -0,0 +1,136 @@ +# A `utcDateTime` property encoded as `rfc7231` generates a sample that parses the value with `time.RFC1123` + +```yaml +generate-samples: true +``` + +## TypeSpec + +```tsp +@armProviderNamespace +namespace Microsoft.Test; + +union ProvisioningState { + string, + Succeeded: "Succeeded", + Failed: "Failed", + Canceled: "Canceled", +} + +model WidgetProperties { + description?: string; + + @encode("rfc7231") + lastExecuted?: utcDateTime; + + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} + +model Widget is TrackedResource { + @path + @key("widgetName") + @segment("widgets") + name: string; +} + +@armResourceOperations +interface Widgets { + put is ArmResourceCreateOrReplaceSync; +} +``` + +## The example inputs + +```json examples/Widgets_put.json +{ + "operationId": "Widgets_put", + "title": "Widgets_put", + "parameters": { + "api-version": "2025-01-01", + "subscriptionId": "00000000-0000-0000-0000-000000000000", + "resourceGroupName": "myResourceGroup", + "widgetName": "myWidget", + "resource": { + "location": "eastus", + "properties": { + "description": "my widget", + "lastExecuted": "05 May 2021 12:00:23 GMT" + } + } + }, + "responses": { + "200": { + "body": { + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Test/widgets/myWidget", + "name": "myWidget", + "type": "Microsoft.Test/widgets", + "location": "eastus", + "properties": { + "description": "my widget", + "lastExecuted": "05 May 2021 12:00:23 GMT", + "provisioningState": "Succeeded" + } + } + } + } +} +``` + +## The generated sample parses the `rfc7231` datetime with `time.RFC1123` + +```go widgets_client_example_test +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package testmodule_test + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "log" + "testmodule" + "time" +) + +// Generated from example definition: Widgets_put.json +func ExampleWidgetsClient_Put() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := testmodule.NewClientFactory("00000000-0000-0000-0000-000000000000", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewWidgetsClient().Put(ctx, "2025-01-01", "myResourceGroup", "myWidget", testmodule.Widget{ + Location: to.Ptr("eastus"), + Properties: &testmodule.WidgetProperties{ + Description: to.Ptr("my widget"), + LastExecuted: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC1123, "05 May 2021 12:00:23 GMT"); return t }()), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res = testmodule.WidgetsClientPutResponse{ + // Widget: testmodule.Widget{ + // ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Test/widgets/myWidget"), + // Name: to.Ptr("myWidget"), + // Type: to.Ptr("Microsoft.Test/widgets"), + // Location: to.Ptr("eastus"), + // Properties: &testmodule.WidgetProperties{ + // Description: to.Ptr("my widget"), + // LastExecuted: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC1123, "05 May 2021 12:00:23 GMT"); return t}()), + // ProvisioningState: to.Ptr(testmodule.ProvisioningStateSucceeded), + // }, + // }, + // } +} +``` From 8937e4af712ebfa786f6f2784cbe4befa9942a49 Mon Sep 17 00:00:00 2001 From: Jiaqi Zhang Date: Tue, 21 Jul 2026 17:36:31 +0800 Subject: [PATCH 5/6] update changelog --- ...copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md b/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md index aa97158211..cbf26001c9 100644 --- a/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md +++ b/.chronus/changes/copilot-fix-invalid-go-rfc7231-datetime-2026-6-21-5-57-23.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-go" --- -Fix the example generator emitting uncompilable Go for `utcDateTime` properties encoded as `rfc7231`. The `RFC7231` time format now maps to the Go `time.RFC1123` layout (`time.Parse`) instead of falling through to the Unix-timestamp `strconv.ParseInt` path. \ No newline at end of file +Fix the example generator emitting incorrect code for `rfc7231` datatime. From 3dc1ab9ab2413bdcf2abf39607d42a1f4ba57ec2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Jul 2026 06:19:24 +0000 Subject: [PATCH 6/6] Revert typespec-go version bump and remove version-bump doc step Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com> --- packages/typespec-go/docs/development.md | 3 +-- packages/typespec-go/package.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/typespec-go/docs/development.md b/packages/typespec-go/docs/development.md index 312573085c..15651432a7 100644 --- a/packages/typespec-go/docs/development.md +++ b/packages/typespec-go/docs/development.md @@ -210,5 +210,4 @@ Before you do, make sure to: 1. Format your code (`pnpm format` from the repo root, or check with `pnpm format:check`). 2. Rebuild and regenerate everything so the committed fixtures reflect your change. -3. Bump the `version` field in `packages/typespec-go/package.json` (a patch bump for a bug fix, a minor bump for a new feature). -4. Add a changelog entry with [Chronus](https://github.com/microsoft/chronus) by running `pnpm change add` from the repo root and following the prompts. This creates a change file under `.chronus/changes/` that you should commit with your PR. +3. Add a changelog entry with [Chronus](https://github.com/microsoft/chronus) by running `pnpm change add` from the repo root and following the prompts. This creates a change file under `.chronus/changes/` that you should commit with your PR. diff --git a/packages/typespec-go/package.json b/packages/typespec-go/package.json index 2145343375..0b72f974cb 100644 --- a/packages/typespec-go/package.json +++ b/packages/typespec-go/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-go", - "version": "0.15.1", + "version": "0.15.0", "author": "Microsoft Corporation", "description": "TypeSpec emitter for Go SDKs", "homepage": "https://azure.github.io/typespec-azure",