DevToolKits.app
Schema 工具

JSON 轉 OpenAPI Schema

貼上 JSON 就能產生 OpenAPI 的元件 schema。
物件與陣列會轉為含必填欄位的 JSON Schema,混合的陣列則以 oneOf 表示。
所有處理都在瀏覽器完成,不會將資料傳送到伺服器。

指南: 使用方式與特色

  • 將 JSON 貼入輸入框後點擊「轉換成 OpenAPI」。
  • 物件會展開為帶 properties 與 required 的 JSON Schema。
  • 陣列會推斷元素型別;若混合多種型別則使用 oneOf。
  • 可使用複製或清除按鈕來重複利用或重新開始。

範例: 輸入與輸出範例

Infer schema from a profile object

輸入範例

{"name":"Jane","email":"jane@example.com","verified":true}

輸出範例

{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "email": {"type": "string", "format": "email"},
    "verified": {"type": "boolean"}
  },
  "required": ["name", "email", "verified"]
}

FAQ: 常見問題

  • 輸出長什麼樣子?

    會建立 components.schemas.Root,並以 JSON Schema 方式包含 properties 與 required。
  • 混合陣列或 null 會如何處理?

    會推斷每個元素,若有多種類型則使用 oneOf,null 則以 nullable: true 表示。
  • 資料會被送到伺服器嗎?

    不會。所有運算都在瀏覽器完成,沒有網路請求。

使用情境: 常見的使用情境

  • Drafting schemas

    Transform JSON samples into OpenAPI schema stubs to seed documentation or mock generation.

  • Sharing endpoint expectations fast

    Convert request/response examples and paste them into PRs or issues to align on contract details.

  • Checking consistency with existing specs

    Compare generated stubs with current definitions to spot fields that need updates.

注意: 注意事項與限制

  • 處理皆在瀏覽器內完成

    輸入與輸出都留在你的裝置,關閉分頁或清除快取時,暫存狀態會被移除。

  • 關鍵資料請再次確認

    結果僅供輔助,放到正式系統或對外分享前請先檢查並依需求驗證。

  • 大型資料仰賴裝置性能

    非常大的文字或檔案在部分瀏覽器可能較慢,建議重度工作時使用桌面環境。

JSON 轉 OpenAPI Schema 產生器

將 JSON 範例轉成 OpenAPI schema,用於 request、response 與 components.schemas 文件化。可以快速建立 schema 初稿,減少手動撰寫每個 property 的時間。

適合使用的情境

  • 文件化 endpoint:從實際回應開始建立 schema。
  • 整理 API 合約:檢查型別、required 欄位與巢狀結構。
  • 準備 Swagger 文件:快速產生 OpenAPI schema 草稿。

format、enum、optional field、array 限制等細節仍需要人工確認。

這個工具的相關文章

Recent Articles