[Bug]: `@encode(string)` int64 default becomes `null`, and numeric examples ignore the encoding
Maintainers usually reply within 1 day
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
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
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/typespec
-
Http-client-js operation response on the client doesn't carry the return typePossibly taken @reginaldalfret claimed this 10 days ago. Openemitter:client:js
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/typespec#11853 · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug]: @terminalEvent on a model-payload variant emits an unconstrained oneOf branch in OpenAPI 3.2 SSE outputPossibly taken @Shubham-Padkonde claimed this 21 days ago. Openbug emitter:openapi3 triaged:core
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/typespec#11747 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug]: [http-server-csharp] Model with a `Record<unknown>[]` property generates C# that does not compile (missing `using System.Text.Json.Nodes;`)May be free again @nightcityblade claimed this 40 days ago, and no pull request is open. Openbug emitter:service:csharp triaged:core
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/typespec#11733 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
emitter:client:java feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/typespec#11076 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug]: http-client-js expand guards use truthy check, dropping falsy values like false and 0May be free again A pull request for this issue was closed without being merged. Openemitter:client:js
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/typespec#10264 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in microsoft/typespec
Similar issues
-
`GET /v1/event/token/{uuid}` can report a BOM upload as done before policy evaluation and metrics have finishedPossibly taken @Zargath claimed this today. Opendefect in triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
DependencyTrack/dependency-track#7646 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
floci-io/floci#5425 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
objectionary/eo-graphs#80 ·
-
WebMvcStreamableServerTransportProvider: idle-session eviction stops permanently after a NullPointerException when a session is deleted mid-sweepPossibly taken @lejuho claimed this today. Openstatus: waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
spring-projects/spring-ai#7133 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
objectionary/jucs#141 ·
Maintainers usually reply within 1 day