Skip to content

[TCGC] Match JSON number example values to decimal/decimal128 properties#4487

Merged
tadelesh merged 2 commits into
release/may-2026from
copilot/tcgc-fix-decimal-type-mismatch
May 25, 2026
Merged

[TCGC] Match JSON number example values to decimal/decimal128 properties#4487
tadelesh merged 2 commits into
release/may-2026from
copilot/tcgc-fix-decimal-type-mismatch

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

JSON number values in example files were silently dropped for properties typed as decimal or decimal128 (e.g. threshold: decimal with example value 80), so they never appeared in the example value set surfaced by TCGC.

getSdkTypeExample in packages/typespec-client-generator-core/src/example.ts routed examples to the numeric branch only for isSdkIntKind / isSdkFloatKind. Fixed-point kinds (decimal, decimal128) belong to SdkFixedPointKindsEnum and fell through the switch, yielding undefined.

Changes

  • interfaces.ts: Export the existing isSdkFixedPointKind predicate.
  • example.ts: Include isSdkFixedPointKind(type.kind) in the numeric dispatch so decimal/decimal128 are handled like other numerics.
  • Tests: Added SdkNumberExample for decimal and SdkNumberExample for decimal128 cases with corresponding fixture JSON files.
// Before
if (isSdkIntKind(type.kind) || isSdkFloatKind(type.kind)) {
  return getSdkBaseTypeExample("number", type, example, relativePath);
}

// After
if (isSdkIntKind(type.kind) || isSdkFloatKind(type.kind) || isSdkFixedPointKind(type.kind)) {
  return getSdkBaseTypeExample("number", type, example, relativePath);
}

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label May 25, 2026
Copilot AI changed the title [WIP] Fix decimal type property match with JSON number value [TCGC] Match JSON number example values to decimal/decimal128 properties May 25, 2026
Copilot AI requested a review from tadelesh May 25, 2026 03:09
@tadelesh tadelesh marked this pull request as ready for review May 25, 2026 03:34
@azure-sdk
Copy link
Copy Markdown
Collaborator

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - fix ✏️

Fix reorderParameters, addParameter, removeParameter, and replaceParameter so that decorators copied to cloned model properties and cloned operations are applied (by calling finishType after cloning). This fixes scenarios such as parameters with @typeChangedFrom under a @versioned service.

@azure-tools/typespec-client-generator-core - fix ✏️

Fix example value matching for decimal and decimal128 typed properties. JSON number values in example files are now correctly recognized as matching decimal / decimal128 typed properties.

@azure-tools/typespec-client-generator-core - feature ✏️

Extend isExactName to additional SDK types whose names can be changed by @clientName: SdkClientType, SdkServiceMethodBase (and its derived method kinds), and SdkEnumValueType. Also fixed SdkClientType.name to strip the internal exact() marker.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-client-generator-core@4487

commit: fffcc51

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

@tadelesh tadelesh merged commit 99fd08a into release/may-2026 May 25, 2026
29 checks passed
@tadelesh tadelesh deleted the copilot/tcgc-fix-decimal-type-mismatch branch May 25, 2026 05:22
tadelesh added a commit that referenced this pull request May 25, 2026
Hotfix release for `@azure-tools/typespec-client-generator-core` 0.69.0

## Changes
- [#4480] Extend `isExactName` to clients, methods, and enum values
- [#4477] Fix
`reorderParameters`/`addParameter`/`removeParameter`/`replaceParameter`
decorator application on cloned types
- [#4487] Fix example value matching for `decimal`/`decimal128`
properties
- [#4484] Fix example values dropped on subtypes added via
`@hierarchyBuilding`

## Checklist
- [x] Version bump via `pnpm chronus version --ignore-policies`
- [x] Only TCGC package changed
- [x] Core submodule pointer unchanged

---------

Co-authored-by: tadelesh <chenjieshi@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TCGC] decimal type property does not match JSON number value in examples

4 participants