Slide 1

Slide 1 text

20150716 - JSON Schema 速習会 Introduction to JSON Schema Masayuki IZUMI - @izumin5210

Slide 2

Slide 2 text

Ƅ Rekimoto Lab. at the University of Tokyo (2008-2015: Akashi-NCT) Ɠ Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.)

Slide 3

Slide 3 text

pry(main)> izumin.skill_ratio Ruby JavaScript Android Design

Slide 4

Slide 4 text

pry(main)> izumin.skill_ratio Ruby JavaScript Android Design

Slide 5

Slide 5 text

「JSON Schema ?」 さいきんよく見かけるけど,一体何者?

Slide 6

Slide 6 text

Q: What does it do? JSON Schema ってなにすんの? A: It describes your JSON data format[1] . JSON のフォーマット記述するやつやで. [1] http://json-schema.org/ 20150716 - JSON Schema 速習会

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

$ 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 とりあえず触ってみましょう

Slide 9

Slide 9 text

/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

Slide 10

Slide 10 text

/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

Slide 11

Slide 11 text

/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/

Slide 12

Slide 12 text

testing

Slide 13

Slide 13 text

レスポンスを適当に弄ってみる

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

[2] https://github.com/r7kamura/rack-json_schema/

Slide 16

Slide 16 text

document $ open http://localhost:5000/doc

Slide 17

Slide 17 text

[2] https://github.com/r7kamura/rack-json_schema/ document $ open http://localhost:5000/doc

Slide 18

Slide 18 text

自分で書いてみる $ bundle exec prmd init -y post > doc/schemata/post.yml [3] https://github.com/interagent/prmd

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

基本構造 - properties title: User description: User object definitions: # 中略 properties: email: "$ref": "/schemata/user#/definitions/email" # 以下略

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

基本構造 - 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 # 以下略

Slide 24

Slide 24 text

基本構造 - 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 # 以下略

Slide 25

Slide 25 text

基本構造 - 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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

結合 $ bundle exec prmd combine \ --meta doc/meta.yml \ doc/schemata > doc/schemata/post.yml