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

5919537a0ecfa5d4dea704cf878ae90e?s=47 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/

5919537a0ecfa5d4dea704cf878ae90e?s=128

toshimaru

December 08, 2015
Tweet

Transcript

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

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

    Web (gunosy.com) » ! RailsΤϯδχΞืूத !
  3. JSON Schema

  4. JSON Schema஌ͬͯΔਓʁ

  5. JSON Schema࢖ͬͨ͜ͱ͋Δਓʁ

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

  7. 2 Types of JSON Schema » JSON Schema » JSON

    Hyper-Schema
  8. JSON Schema » JSONͷ σʔλϑΥʔϚοτ Λهड़͢Δ » ਓؒʹ΋ػցʹ΋Θ͔Γ΍͍͢υΩϡϝϯτ » ϑΥʔϜͰαϒϛοτ͢ΔσʔλͷόϦσʔγϣϯʹ࢖͑Δ

    » ࣗಈςετʹ΋࢖͑Δ => ࠓ೔ͷ͓࿩͸͕ͬͪ͜ϝΠϯ
  9. JSON Hyper-Schema » Web APIͷ࢓༷ Λهड़͢Δ » APIͰظ଴͢ΔσʔλΛJSON SchemaͷܗࣜͰهड़ »

    ೔ຊͰ͸ͬͪ͜ͷํ͕ϙϐϡϥʔʁ
  10. JSON SchemaͰ ίϥϘϨʔγϣϯ

  11. ίϥϘਤ +------------------+ | | | Client-side JS | | (React)

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

    » For Apps » useful for Validation » useful for Test » etc.
  13. For Humans

  14. Repositories » ! Rails API Repo ! » "JSON Schema

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

  16. JSON Schema pull request

  17. GET /users/{id}

  18. # 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
  19. For Apps

  20. JSON Schema Validation require 'json-schema' schema = { "type" =>

    "object", "required" => ["a"], "properties" => { "a" => {"type" => "integer"} } } data = { "a" => 5 } JSON::Validator.validate(schema, data)
  21. 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
  22. Ruby JSON Schema Library » ruby-json-schema/json-schema » brandur/json_schema

  23. json-schema vs json_schema » depending on json-schema: » airbrake/airbrake »

    square/fdoc
  24. json-schema vs json_schema » depending on json_schema: » interagent/committee »

    interagent/prmd » increments/qiita-rb » r7kamura/rack-json_schema » r7kamura/jdoc
  25. JavaScript JSON Schema Library ฐࣾϑϩϯΤϯυΤϯδχΞͷΦεεϝ » mafintosh/is-my-json-valid » epoberezkin/ajv

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

  27. ໧ͬͯYAMLͰॻ͜͏

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

  29. JSON Schemaͷ ࠓͱ͜Ε͔Β » JSON Schema v5 Proposals͕ ग़͞Ε͍ͯΔஈ֊ »

    Issue΍Google GroupsΛ௥͏ͱ Α͛͞ » v5΁ͷ۩ମతͳϩʔυϚοϓ͸Ҿ͔ Ε͍ͯͳ͍໛༷
  30. JSON SchemaίϥϘͰΑ͔ͬͨ͜ ͱ » όοΫΤϯυΤϯδχΞͱϑϩϯτΤϯυΤϯδχΞͷ࢓༷ͷڞ௨ೝ ࣝ » JSON SchemaΛઌʹఆ͓ٛͯ͘͜͠ͱͰόοΫΤϯυΤϯδχΞͱ ϑϩϯτΤϯυΤϯδχΞ͕ૄʹ։ൃͰ͖Δ

    » JSON SchemaͰόάͷࠞೖΛ๷͙
  31. ͋Γ͕ͱ͏͍͟͝·ͨ͠