Skip to content

Fix: [ms] encoded duration default values were being encoded with the wrong format. - #11731

Open
Gerardo Lecaros (glecaros) wants to merge 1 commit into
mainfrom
glecaros/milliseconds
Open

Fix: [ms] encoded duration default values were being encoded with the wrong format.#11731
Gerardo Lecaros (glecaros) wants to merge 1 commit into
mainfrom
glecaros/milliseconds

Conversation

@glecaros

Copy link
Copy Markdown
Member

This pull request fixes an issue with how duration example values are serialized when using the @encode("milliseconds", ...) decorator. Previously, these values were being serialized as ISO 8601 strings instead of numeric values. The update ensures that durations are now correctly serialized as numbers representing milliseconds. The most important changes are:

Bug Fix: Duration Serialization

  • Fixed the serialization logic in packages/compiler/src/lib/examples.ts so that when encoding durations as "milliseconds", the output is a numeric value (integer or float, as appropriate), not an ISO 8601 string.

Testing

  • Added new test cases in packages/compiler/test/decorators/examples.test.ts to verify that durations encoded as milliseconds produce the correct numeric values in both integer and float formats.

Documentation

  • Added a changelog entry in .chronus/changes/fix-duration-milliseconds-example-serialization-2026-8-19-18-30-0.md describing the fix and its impact.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes TypeSpec compiler example serialization for duration values encoded via @encode("milliseconds", ...), ensuring they serialize as numeric millisecond values (rather than ISO 8601 strings), aligned with the intended encoding semantics.

Changes:

  • Added "milliseconds" handling to the duration scalar serializer to emit duration.total({ unit: "milliseconds" }) (floored for integer target scalars).
  • Added unit tests covering both integer and floating-point millisecond encodings.
  • Added a Chronus changelog entry documenting the fix for @typespec/compiler.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/compiler/src/lib/examples.ts Implements millisecond numeric serialization for encoded duration examples.
packages/compiler/test/decorators/examples.test.ts Adds regression tests validating millisecond encoding outputs for int32/float32.
.chronus/changes/fix-duration-milliseconds-example-serialization-2026-8-19-18-30-0.md Documents the fix in the compiler changelog stream.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Fix duration example values being serialized verbatim as an ISO 8601 string instead of a numeric value when encoded with @encode("milliseconds", ...)

@pkg-pr-new

pkg-pr-new Bot commented Aug 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11731

commit: 4a93627

@azure-sdk-automation

azure-sdk-automation Bot commented Aug 19, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants