Slide 1

Slide 1 text

JSON SchemaͰ όοΫΤϯυΤϯδχΞͱ ϑϩϯτΤϯυΤϯδχΞ͕ ίϥϘ͢Δ

Slide 2

Slide 2 text

Self Introduction » @toshimaru_e » Rails Developer @Gunosy » Gunosy Web (gunosy.com) » ! RailsΤϯδχΞืूத !

Slide 3

Slide 3 text

JSON Schema

Slide 4

Slide 4 text

JSON Schema஌ͬͯΔਓʁ

Slide 5

Slide 5 text

JSON Schema࢖ͬͨ͜ͱ͋Δਓʁ

Slide 6

Slide 6 text

JSON Schemaʹ2छྨ ͋Δ͜ͱ஌͍ͬͯΔਓʁ

Slide 7

Slide 7 text

2 Types of JSON Schema » JSON Schema » JSON Hyper-Schema

Slide 8

Slide 8 text

JSON Schema » JSONͷ σʔλϑΥʔϚοτ Λهड़͢Δ » ਓؒʹ΋ػցʹ΋Θ͔Γ΍͍͢υΩϡϝϯτ » ϑΥʔϜͰαϒϛοτ͢ΔσʔλͷόϦσʔγϣϯʹ࢖͑Δ » ࣗಈςετʹ΋࢖͑Δ => ࠓ೔ͷ͓࿩͸͕ͬͪ͜ϝΠϯ

Slide 9

Slide 9 text

JSON Hyper-Schema » Web APIͷ࢓༷ Λهड़͢Δ » APIͰظ଴͢ΔσʔλΛJSON SchemaͷܗࣜͰهड़ » ೔ຊͰ͸ͬͪ͜ͷํ͕ϙϐϡϥʔʁ

Slide 10

Slide 10 text

JSON SchemaͰ ίϥϘϨʔγϣϯ

Slide 11

Slide 11 text

ίϥϘਤ +------------------+ | | | Client-side JS | | (React) | | | +---+--------+-----+ | ^ | | +---------------+ | JSON | <-------- | JSON Schema | | | +---------------+ v | +---+--------+-----+ | | | Server-side API | | (Rails) | | | +------------------+

Slide 12

Slide 12 text

JSON Schema for us » For Humans » Clear specification » For Apps » useful for Validation » useful for Test » etc.

Slide 13

Slide 13 text

For Humans

Slide 14

Slide 14 text

Repositories » ! Rails API Repo ! » "JSON Schema Repo# » $ Frontend Repo $

Slide 15

Slide 15 text

Workflow 1.ඞཁͳAPIͱͦ͜ʹؚ·ΕΔ΂͖σʔλΛચ͍ग़͠ 2.1ΛJSON Schemaʹམͱ͜͠Ή 3.ϓϧϦΫʂ

Slide 16

Slide 16 text

JSON Schema pull request

Slide 17

Slide 17 text

GET /users/{id}

Slide 18

Slide 18 text

# user.schema.yml $schema: http://json-schema.org/draft-04/schema# title: User description: An User type: object properties: id: type: integer email: type: string format: email name: type: string minLength: 1 maxLength: 32 required: - id - email - name

Slide 19

Slide 19 text

For Apps

Slide 20

Slide 20 text

JSON Schema Validation require 'json-schema' schema = { "type" => "object", "required" => ["a"], "properties" => { "a" => {"type" => "integer"} } } data = { "a" => 5 } JSON::Validator.validate(schema, data)

Slide 21

Slide 21 text

RSpec JSON Schema Matcher 1 describe "Fetching the current user" do context "with valid auth token" do it "returns the current user" do user = create(:user) auth_header = { "Auth-Token" => user.auth_token } get v1_current_user_url, {}, auth_header expect(response.status).to eq 200 expect(response).to match_response_schema("user") end end end 1 Validating JSON Schemas with an RSpec Matcher

Slide 22

Slide 22 text

Ruby JSON Schema Library » ruby-json-schema/json-schema » brandur/json_schema

Slide 23

Slide 23 text

json-schema vs json_schema » depending on json-schema: » airbrake/airbrake » square/fdoc

Slide 24

Slide 24 text

json-schema vs json_schema » depending on json_schema: » interagent/committee » interagent/prmd » increments/qiita-rb » r7kamura/rack-json_schema » r7kamura/jdoc

Slide 25

Slide 25 text

JavaScript JSON Schema Library ฐࣾϑϩϯΤϯυΤϯδχΞͷΦεεϝ » mafintosh/is-my-json-valid » epoberezkin/ajv

Slide 26

Slide 26 text

JSONॻ͘ͷπϥ͍໰୊ » ʮด͡Χοί͕ʔ!!ʯ » ʮΧϯϚ͕ʔ!!!!ʯ » ʮίϝϯτ͕ʔ!!!!!!ʯ » ʮΫΦςʔγϣϯ͕ʔ!!!!!!ʯ

Slide 27

Slide 27 text

໧ͬͯYAMLͰॻ͜͏

Slide 28

Slide 28 text

JSON Schemaͷࠓͱ͜Ε͔Β » json-schema/json-schema

Slide 29

Slide 29 text

JSON Schemaͷ ࠓͱ͜Ε͔Β » JSON Schema v5 Proposals͕ ग़͞Ε͍ͯΔஈ֊ » Issue΍Google GroupsΛ௥͏ͱ Α͛͞ » v5΁ͷ۩ମతͳϩʔυϚοϓ͸Ҿ͔ Ε͍ͯͳ͍໛༷

Slide 30

Slide 30 text

JSON SchemaίϥϘͰΑ͔ͬͨ͜ ͱ » όοΫΤϯυΤϯδχΞͱϑϩϯτΤϯυΤϯδχΞͷ࢓༷ͷڞ௨ೝ ࣝ » JSON SchemaΛઌʹఆ͓ٛͯ͘͜͠ͱͰόοΫΤϯυΤϯδχΞͱ ϑϩϯτΤϯυΤϯδχΞ͕ૄʹ։ൃͰ͖Δ » JSON SchemaͰόάͷࠞೖΛ๷͙

Slide 31

Slide 31 text

͋Γ͕ͱ͏͍͟͝·ͨ͠