Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Bug]: `@encode(string)` int64 default becomes `null`, and numeric examples ignore the encoding

Open Beginner friendly
#12,059 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Om-singhaI is already working on this.

Since Sep 29, 2026.

  • #12060 by @Om-singhaI — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
openapi
Domain
api

Research direction

Start in packages/compiler/src/lib/examples.ts and read serializeValueAsJson, focusing on its NumericValue handling and the property's resolved @encode. Reproduce the supplied Account model and inspect the OpenAPI output for defaults and examples. Done means encoded int64 and decimal values are emitted as strings, including the large int64 default, rather than null or JSON numbers.

Written by the indexing model from the issue text.

Description

bug compiler:core triaged:core
Describe the bug

With @encode(string) id: int64 = 9007199254740993, the OpenAPI output has "default": null, so the value is lost. Other defaults and @example values on @encode(string) int64 and decimal properties come out as JSON numbers, which don't match the type: string next to them.

serializeValueAsJson in packages/compiler/src/lib/examples.ts already resolves the property's @encode, but the NumericValue case returns asNumber() without checking it, and asNumber() gives null when a JS number can't hold the value exactly. Dates and durations already use the encoding in that function (#11731 fixed the milliseconds case). Happy to send a PR.

Reproduction
@example(#{ id: 42, balance: 1050.25 })
model Account {
  @encode(string) id: int64 = 9007199254740993;
  @encode(string) balance: decimal = 0;
}

OpenAPI 3.0.0 output on current main. 3.1.0 and 3.2.0 give the same defaults.

"properties": {
  "id": { "type": "string", "format": "int64", "default": null },
  "balance": { "type": "string", "format": "decimal", "default": 0 }
},
"example": { "id": 42, "balance": 1050.25 }

Expected "9007199254740993" and "0" for the defaults, and { "id": "42", "balance": "1050.25" } for the example.

Dominant language
Java
Stars
5.9k
Forks
403
Avg merge
3d 11h
Merged PRs (30d)
96

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/typespec

All issues in microsoft/typespec

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.