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

JSON Schemaでバックエンドエンジニアとフロントエンドエンジニアがコラボする / js...

toshimaru
December 08, 2015

JSON Schemaでバックエンドエンジニアとフロントエンドエンジニアがコラボする / json-schema-collaboration

『エムスリー x Gunosy Beer bash』( http://gunosy-beer.connpass.com/event/22825/ ) での発表スライドです。

- 内容をまとめたBlog記事はこちら: http://blog.toshimaru.net/json-schema-collaboration/

toshimaru

December 08, 2015
Tweet

More Decks by toshimaru

Other Decks in Technology

Transcript

  1. Self Introduction » @toshimaru_e » Rails Developer @Gunosy » Gunosy

    Web (gunosy.com) » ! RailsΤϯδχΞืूத !
  2. ίϥϘਤ +------------------+ | | | Client-side JS | | (React)

    | | | +---+--------+-----+ | ^ | | +---------------+ | JSON | <-------- | JSON Schema | | | +---------------+ v | +---+--------+-----+ | | | Server-side API | | (Rails) | | | +------------------+
  3. JSON Schema for us » For Humans » Clear specification

    » For Apps » useful for Validation » useful for Test » etc.
  4. # 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
  5. JSON Schema Validation require 'json-schema' schema = { "type" =>

    "object", "required" => ["a"], "properties" => { "a" => {"type" => "integer"} } } data = { "a" => 5 } JSON::Validator.validate(schema, data)
  6. 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
  7. json-schema vs json_schema » depending on json_schema: » interagent/committee »

    interagent/prmd » increments/qiita-rb » r7kamura/rack-json_schema » r7kamura/jdoc
  8. JSON Schemaͷ ࠓͱ͜Ε͔Β » JSON Schema v5 Proposals͕ ग़͞Ε͍ͯΔஈ֊ »

    Issue΍Google GroupsΛ௥͏ͱ Α͛͞ » v5΁ͷ۩ମతͳϩʔυϚοϓ͸Ҿ͔ Ε͍ͯͳ͍໛༷