Swagger Open API Spec (JSON Schema)から
Drupal Contents Type、Entity Typeを
自動的に生成する試み
DRUPAL CAMP
January 14, 2017
Kyotaro Kon
Color Balance
— Self Introduction —
Kyotaro Kon
フリーランス Drupalデベロッパー
札幌在住
現在英会話学校に通うためタイに滞在中
Open APIとは?
• RESTful APIのインターフェイスを記述するための
標準フォーマットを推進する団体「Open API
Initiative」が、The Linux Foundationの協力のもと
でマイクロソフト、Google、Apigeeなどにより結
成
• Swagger Specificationが寄贈され、OpenAPI
Specificationとリネームされる
Swagger Specificationとは
• REST APIを記述する標準仕様
• Yamlまたはjsonで記述する
• パス及びメソッドによりオペレーションを定義
• モデルの定義にJSON Schemaを利用
• swagger.ioが様々なツールを提供
order_contact_tel:
type: string
minLength: 1
maxLength: 15
primary_dns:
type: string
maxLength: 15
primary_wins:
type: string
maxLength: 15
redundancy:
type: string
minLength: 1
maxLength: 20
re_line_id:
type: string
maxLength: 20
re_redundancy:
type: string
maxLength: 20
re_servicetype:
type: string
maxLength: 50
re_width:
type: string
maxLength: 5
re_location_address:
type: string
maxLength: 200
re_location_dev_name:
type: string
maxLength: 200
secondary_dns:
type: string
maxLength: 15
secondary_wins:
type: string
maxLength: 15
servicetype:
type: string
minLength: 1
maxLength: 50
start_dhcp:
type: string
maxLength: 15
summarize_netmask:
type: int
minLength: 1
maxLength: 2
summarize_netmask1:
type: int
Swagger API Entity モジュール
Drupal8
Swagger API Entity module
Swagger
Swagger Converter
Swagger API Entity
Configuration API
Swagger Processor
Entity API
Swagger
Manager
Drupal8 Configuration API
• 従来$confや各々のテーブルに保存されていたものをConfig
として管理可能
• 各モジュールで定義したスキーマ通り保存され、配列やネス
トも可能
• コンフィグ全体の保存方法としてDBやファイルを選択でき
る
• 永続的なほとんどのデータがコンフィグを利用
• インポート、エクスポートが可能
Drupal8 Entity API
• 汎用的なメソッドを抽象化し一貫性のあるインター
フェイスを提供するするための仕組み
• CRUD以外にURLハンドリングや一覧を提供する
• Configuration Entityを利用することで設定のコンフ
ィグ化が可能(Node, Viewsなど)
Import Swagger
Drupal8
Swagger API Entity module
Swagger
Swagger Converter
Swagger API Entity
Configuration API
Swagger Processor
Entity API
Swagger
Manager
• Swaggerを解析し対応するコンフィグへ変換す
• モデルをDrupalのエンティティとして定義
• 拡張表現を使いエンティティの表示方法を設定可能
Swagger API Entity
Drupal8
Swagger API Entity module
Swagger
Swagger Converter
Swagger API Entity
Configuration API
Swagger Processor
Entity API
Swagger
Manager
• 専用設計のエンティティ
• コンテンツのデータを持たないストレージ
• CRUDリクエスト毎にAPIをコール
• JSON Schemaからのバリデーション
Future Development
今後必要な機能
• リレーション
親子関係
• ユーザーコンテキスト
グローバル及びAPI単位のステータスなど
• Views対応
• 権限、Export、通知、統計など
単独Webアプリケーション
API化
統合Webアプリケーション
エンタープライズアプリケーションへの可能性
• 既存のアプリケーションを活用出来る
• 既存のデータ資産を活用出来る
• 内部構造を外部に公開せずに済む
• 画面設計などをSwagger及びUIで行える
• はるかにローコストである
“Do we have the spirit of enterprise?”

Create entity from swagger in drupal8