Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#12,059 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Om-singhaI がすでに取り組んでいます。

2026年9月29日 から。

  • #12060 @Om-singhaI による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
openapi
領域
api

調査の方向性

packages/compiler/src/lib/examples.ts から始めて serializeValueAsJson を読み、NumericValue の処理とプロパティの解決済み @encode に注目してください。提供された Account モデルを再現し、デフォルト値と例について OpenAPI の出力を確認してください。エンコードされた int64 と decimal の値が、巨大な int64 のデフォルト値を含め、null や JSON の数値ではなく文字列として出力されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
5.9k
フォーク
403
平均マージ
3日 8時間
マージ済み PR(30日)
101

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/typespec のほかの issue

microsoft/typespec の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。