📐

JSON Schema 產生器

貼一段 API response 範例,一鍵推出對應 JSON Schema (draft-07)。 可用於 pytest 驗 response 結構(見 API 測試實戰)。

📥 輸入 JSON
📤 JSON Schema 輸出
📖 在 pytest 用這個 schema 驗證 API response
from jsonschema import validate

USER_SCHEMA = {
  "type": "object",
  "required": ["id", "email"],
  "properties": { ... }  # 貼這裡產出的內容
}

def test_get_user(api, user_id):
    resp = api.get(f'/users/{user_id}')
    assert resp.status_code == 200
    validate(resp.json(), USER_SCHEMA)