Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to JSON Schema

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Introduction to JSON Schema

Avatar for izumin5210

izumin5210

July 16, 2015
Tweet

More Decks by izumin5210

Other Decks in Technology

Transcript

  1. Ƅ Rekimoto Lab. at the University of Tokyo (2008-2015: Akashi-NCT)

    Ɠ Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.)
  2. Q: What does it do? JSON Schema ってなにすんの? A: It

    describes your JSON data format[1] . JSON のフォーマット記述するやつやで. [1] http://json-schema.org/ 20150716 - JSON Schema 速習会
  3. What is JSON Schema ? 20150716 - JSON Schema 速習会

    * Defines structure of JSON data - JSON Schema Core * Provides structual validation - JSON Schema Validation * Defines hyper{text,media} related things - JSON Hyper Schema
  4. $ git clone https://github.com/izumin5210/jsonschema-study.git $ cd jsonschema-study # branch 名はお好みでどうぞ

    $ git checkout -b hands-on refs/tags/entrypoint # path 不要な人は省略してください $ bundle install --path vendor/bundle $ RACK_ENV=mock bundle exec rackup config.ru -p 5000 $ open http://localhost:5000/api/users とりあえず触ってみましょう
  5. /api/users [ { "created_at": "2015...", "id": 1, "name": "Masayuki IZUMI",

    "updated_at": "2015..." } ] namespace '/api' do get '/users' do json [] end end /api/users app.rb
  6. /api/users [ { "created_at": "2015...", "id": 1, "name": "Masayuki IZUMI",

    "updated_at": "2015..." } ] namespace '/api' do get '/users' do json [] end end /api/users app.rb
  7. /api/users [ { "created_at": "2015...", "id": 1, "name": "Masayuki IZUMI",

    "updated_at": "2015..." } ] namespace '/api' do get '/users' do json [] end end /api/users app.rb [2] https://github.com/r7kamura/rack-json_schema/
  8. 基本構造 title: User description: User object definitions: # 属性等の定義 links:

    # API の定義(厳密にはチョットチガウ) properties: # 属性の定義(defeinitions への参照が多い)
  9. 基本構造 - definitions title: User description: User object definitions: email:

    description: email address type: string format: email # 以下略
  10. 基本構造 - properties title: User description: User object definitions: #

    中略 properties: email: "$ref": "/schemata/user#/definitions/email" # 以下略
  11. title: User description: User object definitions: # 中略 properties: email:

    "$ref": "/schemata/user#/definitions/email" # 以下略 基本構造 - properties "$ref": "#/foo/bar" JSON Reference[4] #/foo/bar JSON Pointer[5] [4] http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 [5] http://tools.ietf.org/html/rfc6901
  12. 基本構造 - links title: User description: User object definitions: #

    中略 links: - description: Info for existing user. href: "/api/users/{(%2Fschemata%2Fuser%23definitions%2Fid)}" method: GET rel: self title: Info # 以下略
  13. 基本構造 - links title: User description: User object definitions: #

    中略 links: - description: Info for existing user. href: "/api/users/{(%2Fschemata%2Fuser%23definitions%2Fid)}" method: GET rel: self title: Info # 以下略
  14. 基本構造 - links title: User description: User object definitions: #

    中略 links: - description: Info for existing user. href: "/api/users/{(%2Fschemata%2Fuser%23definitions%2Fid)}" method: GET rel: self title: Info # 以下略 "/foo/bar/{(%23baz)}" URI Template[6] [6] http://tools.ietf.org/html/rfc6570
  15. 基本構造 - links # 略 links: - description: Create a

    new user. href: "/api/users" method: POST rel: self schema: properties: # 属性の定義 type: - object title: Create # 以下略
  16. 基本構造 - links # 略 links: - description: Create a

    new user. href: "/api/users" method: POST rel: self schema: properties: # 属性の定義 type: - object title: Create # 以下略
  17. 基本構造 - links # 略 links: - description: Create a

    new user. href: "/api/users" method: POST rel: self schema: properties: # 属性の定義 type: - object title: Create # 以下略
  18. 結合 $ bundle exec prmd combine \ --meta doc/meta.yml \

    doc/schemata > doc/schemata/post.yml