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.
Describe the bug
With
@encode(string) id: int64 = 9007199254740993, the OpenAPI output has"default": null, so the value is lost. Other defaults and@examplevalues on@encode(string)int64anddecimalproperties come out as JSON numbers, which don't match thetype: stringnext to them.serializeValueAsJsoninpackages/compiler/src/lib/examples.tsalready resolves the property's@encode, but theNumericValuecase returnsasNumber()without checking it, andasNumber()givesnullwhen 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
OpenAPI 3.0.0 output on current main. 3.1.0 and 3.2.0 give the same defaults.
Expected
"9007199254740993"and"0"for the defaults, and{ "id": "42", "balance": "1050.25" }for the example.