Subscribed unsubscribe Subscribe Subscribe

Augmented Usamimi

it { is_expected.to be_blog.written_by(izumin5210) }

JSON Schemaを少しでも楽に使う

Ruby Ruby on Rails JSON Schema Web API

gems

# Gemfile
# ...

gem 'rack-json_schema'

group :development do

  # ...

  gem 'prmd'
  gem 'jdoc'
end

usage

yamlで書けるのは楽.jsonよりは….

# doc/meta.yml
---
"$schema": http://json-schema.org/draft-04/hyper-schema
description: A schema forGochiusa API
id: gochiusa
links:
- href: http://api.example.com/
  rel: self
title: Gochiusa API
# 生成
$ prmd init -y user -o doc/schemata/user.yml
$ prmd init -y post -o doc/schemata/post.yml

# 結合
$ prmd combine --meta doc/meta.yml -o doc/schema.json doc/schemata

# 検証
$ prmd verify doc/schema.json

# ドキュメント生成
$ jdoc doc/schema.json > doc/api.md

まだつらさは多分にあるが,うまく活用して手を抜いていきたい.