SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
  Swaggerで簡単
  APIドキュメント作成
2016.8.30  Tue
⼩小⾕谷松  丈樹
出張!雲勉  in  Tokyo
勉強会/開発者向け
⾃自⼰己紹介
⾃自⼰己紹介(軽くね、かる〜~く
•  アイレット  cloudpack開発事業部
•  セクションリーダー  ⼩小⾕谷松丈樹(おやまつ)
•  主に使⽤用している⾔言語
⾃自⼰己紹介(軽くね、かる〜~く
•  アイレット  cloudpack開発事業部
•  セクションリーダー  ⼩小⾕谷松丈樹(おやまつ)
•  主に使⽤用している⾔言語
•  ⽇日本語
•  ベトナム⼈人教育セクション
•  チームの⽇日本⼈人不不⾜足が深刻化
•  PHP歴5年年
•  リーダー歴2ヶ⽉月
•  最近プロマネメインに転向
Swaggerとは
Swaggerとは
•  ソースコード内のアノテーションから
APIドキュメントを作れる
•  アノテーションの形式化
•  Swagger-‐‑‒UIで実際にAPIリクエストを投げられる
•  つまり、何がいいのさ
ソースコードのコメント品質向上
•  たまに⾒見見るこんなやつも
•  こんなふうに
•  なるといいな(遠い⽬目
/**	
  	
  
	
  	
  *	
  この関数はいつか消す	
  
	
  	
  *	
  例外は握りつぶす	
  
	
  	
  */	
/**	
  	
  
	
  	
  *	
  このメソッドのリクエストURLはこれで	
  
	
  	
  *	
  リクエストパラメータはこれが必須で	
  
	
  	
  *	
  リターンはこんな形で	
  
	
  	
  *	
  例外発生時はこうなって...	
  
	
  	
  */
仕事の役割分担
•  APIドキュメントをまとめるのはPMの仕事?
•  😩.oO(こういう    のとか
          こういう    アイコンって重いんだよなぁ
•  ソースコード=APIドキュメント
•  これならプログラマの領領分
•  PM「しめしめ」
•  ソースコードと同時にAPIドキュメントも更更新
•  改修を加え続ける案件でもドキュメントが常に最新
開発者に優しい
•  Swagger-‐‑‒UI
•  実際にAPIを叩けるドキュメント
•  単体テストが楽
•  APIを使う側も分かりやすい
Swagger-­‐UIデモサイト h1p://petstore.swagger.io/
Swagger  のいいところ
•  ソースコードのコメント品質向上
•  PMの仕事をプログラマに渡せる
•  重いアプリケーションを開かなくていい
•  仕様変更更が多くてもドキュメントが追いてけぼりにならない
•  APIの単体テストが楽
•  APIリクエストを確認できる
•  などなど
Swagger  って
で、どう書くの?
Swagger-‐‑‒PHP  v2.x
アプリケーション全体の説明
/**	
  
	
  *	
  @SWGSwagger(	
  
	
  *	
  	
  	
  	
  	
  schemes={"h-p"},	
  
	
  *	
  	
  	
  	
  	
  host="localhost",	
  
	
  *	
  	
  	
  	
  	
  basePath="/",	
  
	
  *	
  	
  	
  	
  	
  @SWGInfo(	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  version="1.0.0",	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  >tle="出張!雲勉 in	
  Tokyo登壇デモAPI",	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  descrip>on="あんなことやこんなことをするAPI"	
  
	
  *	
  	
  	
  	
  	
  )	
  
	
  *	
  )	
  
	
  */	
  
•  @SWGInfo
モデルの定義
/**	
  
	
  *	
  @SWGDefini2on(	
  
	
  *	
  	
  	
  	
  	
  defini>on="user",	
  
	
  *	
  	
  	
  	
  	
  @SWGProperty(property="user_id",	
  type="integer",	
  descrip>on="ユーザID"),	
  
	
  *	
  	
  	
  	
  	
  @SWGProperty(property="name",	
  type="string",	
  descrip>on="ユーザ名"),	
  
	
  *	
  	
  	
  	
  	
  @SWGProperty(property="job",	
  type="string",	
  descrip>on="仕事")	
  
	
  *	
  )	
  
	
  */	
  
•  @SWGDefini2on
モデルの定義(こう書いても良良いかも
/**	
  
	
  *	
  @SWGDefini>on(defini>on="user")	
  
	
  */	
  
class	
  User	
  extends	
  Model	
  
{	
  
	
  /**	
  
	
   	
  	
  	
  *	
  @SWGProperty(property="user_id”,	
  type="integer",	
  descrip>on="ユーザID")	
  
	
  	
  	
  */	
  
	
  	
  	
  public	
  $user_id;	
  
	
  	
  
	
  	
  	
  /**	
  
	
  	
  	
  	
  *	
  @SWGProperty(property="name",	
  	
  type="string",	
  descrip>on="ユーザ名")	
  
	
  	
  	
  	
  */	
  
	
  	
  	
  public	
  $name;	
  
	
  
	
  	
  	
  /**	
  
	
  	
  	
  	
  *	
  @SWGProperty(property="job”,	
  type="string",	
  descrip>on="仕事")	
  
	
  	
  	
  	
  */	
  
	
  	
  	
  public	
  $job;	
  
•  @SWGDefini2on	
同じ!
APIの定義
/**	
  
	
  *	
  @SWGGet(	
  
	
  *	
  	
  	
  	
  	
  path=“/user”,	
  
	
  *	
  	
  	
  	
  	
  summary=“ユーザ情報取得”,	
  
	
  *	
  	
  	
  	
  	
  descrip>on=“コンストラクタで設定されたユーザ情報の取得",	
  
	
  *	
  	
  	
  	
  	
  produces={"applica>on/json","applica>on/xml"},	
  
	
  *	
  	
  	
  	
  	
  @SWGResponse(	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  response=200,	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  descrip>on="successful	
  opera>on",	
  
	
  *	
  	
  	
  	
  	
  	
  	
  	
  	
  @SWGSchema(ref="#/defini>ons/user")	
  
	
  *	
  	
  	
  	
  	
  )	
  
	
  *	
  )	
  
	
  */	
  
•  @SWGGet,	
  @SWGPost,	
  @SWGPut,	
  .....
アノテーション書いてどうすんの?
Swaggervel
Swaggervel
•  PHPフレームワーク  Laravel  向けに作られたパッケージ
•  Swagger-‐‑‒php  と  Swagger-‐‑‒ui  を内包
•  composer  require  jlapp/swaggervel:master-‐‑‒dev
h1ps://laravel-­‐news.com/2015/01/swagger-­‐laravel/
Swaggervel
•  Installation
•  Add  Jlapp\Swaggervel\SwaggervelServiceProvider  to  
your  providers  array  in  app/config/app.php
•  Run  php  artisan  vendor:publish  to  push  swagger-‐‑‒ui  to  
your  public  folder
•  ↑コマンドを叩くと
public/下に
ファイルができる
Swaggervel
•  JSON  を吐き出すコマンド
$  vendor/bin/swagger  app/Http/Controllers  -‐‑‒o  public/docs
•  public/docs/swagger.json
{	
  
	
  	
  	
  	
  "swagger":	
  "2.0",	
  
	
  	
  	
  	
  "info":	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "Ntle":	
  "u51fau5f35uff01u96f2ufa33	
  in	
  Tokyou767bu58c7u30c7u30e2API",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "descripNon":	
  "u3042u3093u306au3053u3068u3084u3053u3093u306a...",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "version":	
  "1.0.0"	
  
	
  	
  	
  	
  },	
  
	
  	
  	
  	
  "host":	
  "localhost",	
  
	
  	
  	
  	
  "basePath":	
  "/",	
  
	
  	
  	
  	
  "schemes":	
  [	
  
	
  	
  	
  	
  	
  	
  	
  	
  "h1p"	
  
	
  	
  	
  	
  ],	
  
	
  	
  	
  	
  "paths":	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "/user":	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "get":	
  {	
  ...
Swaggervel
•  http://SERVER_̲NAME/api/docs  にアクセス
•  http://SERVER_̲NAME/docs/swagger.json  を読みこませる
user_id	
  :	
  int	
  
name	
  :	
  string	
  
job	
  :	
  string	
  
→	
  定義した通り!
Swaggervel
•  http://SERVER_̲NAME/api/docs  にアクセス
•  http://SERVER_̲NAME/docs/swagger.json  を読みこませる
user_id	
  :	
  int	
  
name	
  :	
  string	
  
job	
  :	
  string	
  
→	
  定義した通り!
動く!
Swagger  って
まとめ
Swaggerを使う流流れ
•  プログラム+Swagger定義を書く
→  アノテーションからJSONを作るコマンドを実⾏行行
→  ローカル環境のSwagger-‐‑‒UIで動作確認
→  問題無ければcommit
•  サーバ上のSwagger-‐‑‒UIでQAテスト
•  API使う側もSwagger-‐‑‒UIを⾒見見ながらリクエストを作成
本⽇日のまとめ(軽くね、かる〜~く
•  Swagger  って、ええやん!
•  ソースコードの品質向上
•  PMが楽できる  ←最⾼高!
•  インタラクティブAPIドキュメント  ←たのしい!
本⽇日のまとめ(軽くね、かる〜~く
•  Swagger  って、ええやん!
•  ソースコードの品質向上
•  PMが楽できる  ←最⾼高!
•  インタラクティブAPIドキュメント  ←たのしい!
•  Swaggerで楽したいエンジニア、来たれ!
•  サーバーサイド・フロントエンドエンジニア、マネージャー様!
cloudpackでは、
開発エンジニア/インフラエンジニア/デザイナー  鋭意募集中!
http://cloudpack.jp/recruit

Weitere ähnliche Inhalte

Was ist angesagt?

Sledge recently in Yokohama.pm Aug, 2008
Sledge recently in Yokohama.pm Aug, 2008Sledge recently in Yokohama.pm Aug, 2008
Sledge recently in Yokohama.pm Aug, 2008
Yoshiki Kurihara
 
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3techConsumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Toshiaki Maki
 

Was ist angesagt? (20)

One Time Binding & Digest Loop
One Time Binding & Digest LoopOne Time Binding & Digest Loop
One Time Binding & Digest Loop
 
Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発Swaggerで始めるモデルファーストなAPI開発
Swaggerで始めるモデルファーストなAPI開発
 
laravel x モバイルアプリ
laravel x モバイルアプリlaravel x モバイルアプリ
laravel x モバイルアプリ
 
Isomorphic web development with scala and scala.js
Isomorphic web development  with scala and scala.jsIsomorphic web development  with scala and scala.js
Isomorphic web development with scala and scala.js
 
Angular js はまりどころ
Angular js はまりどころAngular js はまりどころ
Angular js はまりどころ
 
【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.js【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.js
 
AWS Lambdaのテストで役立つ各種ツール
AWS Lambdaのテストで役立つ各種ツールAWS Lambdaのテストで役立つ各種ツール
AWS Lambdaのテストで役立つ各種ツール
 
Jsug2015 summer spring適用におけるバッドノウハウとベタープラクティス
Jsug2015 summer spring適用におけるバッドノウハウとベタープラクティスJsug2015 summer spring適用におけるバッドノウハウとベタープラクティス
Jsug2015 summer spring適用におけるバッドノウハウとベタープラクティス
 
Springを使ったwebアプリにリファクタリングしよう
Springを使ったwebアプリにリファクタリングしようSpringを使ったwebアプリにリファクタリングしよう
Springを使ったwebアプリにリファクタリングしよう
 
Java web application testing
Java web application testingJava web application testing
Java web application testing
 
angular1脳で見るangular2
angular1脳で見るangular2angular1脳で見るangular2
angular1脳で見るangular2
 
2016/12/17 ASP.NET フロントエンドタスク入門
 2016/12/17 ASP.NET フロントエンドタスク入門 2016/12/17 ASP.NET フロントエンドタスク入門
2016/12/17 ASP.NET フロントエンドタスク入門
 
Java + React.jsでSever Side Rendering #reactjs_meetup
Java + React.jsでSever Side Rendering #reactjs_meetupJava + React.jsでSever Side Rendering #reactjs_meetup
Java + React.jsでSever Side Rendering #reactjs_meetup
 
One-time Binding & $digest
One-time Binding & $digestOne-time Binding & $digest
One-time Binding & $digest
 
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみアメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
アメブロ2016 アメブロフロント刷新にみる ひかりとつらみ
 
これから始めるSpringのwebアプリケーション
これから始めるSpringのwebアプリケーションこれから始めるSpringのwebアプリケーション
これから始めるSpringのwebアプリケーション
 
capybara で快適なテスト生活を
capybara で快適なテスト生活をcapybara で快適なテスト生活を
capybara で快適なテスト生活を
 
Sledge recently in Yokohama.pm Aug, 2008
Sledge recently in Yokohama.pm Aug, 2008Sledge recently in Yokohama.pm Aug, 2008
Sledge recently in Yokohama.pm Aug, 2008
 
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3techConsumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
 
Node.js version16の新機能
Node.js version16の新機能Node.js version16の新機能
Node.js version16の新機能
 

Andere mochten auch

Reference Letter (Sagetis Biotech) GREGORY COUE
Reference Letter (Sagetis Biotech) GREGORY COUEReference Letter (Sagetis Biotech) GREGORY COUE
Reference Letter (Sagetis Biotech) GREGORY COUE
Grégory Coué
 
Hills noah
Hills noahHills noah
Hills noah
Matthew
 
Dutch bike co seo audit
Dutch bike co seo auditDutch bike co seo audit
Dutch bike co seo audit
kstasiak
 
Uncertainty and Contradiction in Multi-agent Systems
Uncertainty and Contradiction in Multi-agent SystemsUncertainty and Contradiction in Multi-agent Systems
Uncertainty and Contradiction in Multi-agent Systems
Catherine Vorobiova
 
Aula5 contabilidad
Aula5 contabilidadAula5 contabilidad
Aula5 contabilidad
alfred_11
 
Reference Letter (GE) Grégory Coué
Reference Letter (GE) Grégory CouéReference Letter (GE) Grégory Coué
Reference Letter (GE) Grégory Coué
Grégory Coué
 

Andere mochten auch (19)

Jawsug chiba API Gateway
Jawsug chiba API GatewayJawsug chiba API Gateway
Jawsug chiba API Gateway
 
OpenAPI Specification概要
OpenAPI Specification概要OpenAPI Specification概要
OpenAPI Specification概要
 
Understanding how to use Swagger and its tools
Understanding how to use Swagger and its toolsUnderstanding how to use Swagger and its tools
Understanding how to use Swagger and its tools
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 
API Design first with Swagger
API Design first with SwaggerAPI Design first with Swagger
API Design first with Swagger
 
【講演資料】激変する自動車業界におけるクルマ屋の戦略
【講演資料】激変する自動車業界におけるクルマ屋の戦略【講演資料】激変する自動車業界におけるクルマ屋の戦略
【講演資料】激変する自動車業界におけるクルマ屋の戦略
 
Slides Earth Charter Pilar 3 English: Social and Economic Justice
Slides Earth Charter Pilar 3 English: Social and Economic JusticeSlides Earth Charter Pilar 3 English: Social and Economic Justice
Slides Earth Charter Pilar 3 English: Social and Economic Justice
 
Organisation Internationale de La Francophonie
Organisation Internationale de La FrancophonieOrganisation Internationale de La Francophonie
Organisation Internationale de La Francophonie
 
Earth Charter Pilar 1 English: Respect and Care for the Community of Life
Earth Charter Pilar 1 English: Respect and Care for the Community of LifeEarth Charter Pilar 1 English: Respect and Care for the Community of Life
Earth Charter Pilar 1 English: Respect and Care for the Community of Life
 
Reference Letter (Sagetis Biotech) GREGORY COUE
Reference Letter (Sagetis Biotech) GREGORY COUEReference Letter (Sagetis Biotech) GREGORY COUE
Reference Letter (Sagetis Biotech) GREGORY COUE
 
Hills noah
Hills noahHills noah
Hills noah
 
Dutch bike co seo audit
Dutch bike co seo auditDutch bike co seo audit
Dutch bike co seo audit
 
Uncertainty and Contradiction in Multi-agent Systems
Uncertainty and Contradiction in Multi-agent SystemsUncertainty and Contradiction in Multi-agent Systems
Uncertainty and Contradiction in Multi-agent Systems
 
Successful business communications
Successful business communicationsSuccessful business communications
Successful business communications
 
Aula5 contabilidad
Aula5 contabilidadAula5 contabilidad
Aula5 contabilidad
 
Reference Letter (GE) Grégory Coué
Reference Letter (GE) Grégory CouéReference Letter (GE) Grégory Coué
Reference Letter (GE) Grégory Coué
 
Online shopping guide
Online shopping guideOnline shopping guide
Online shopping guide
 
Joint in our body -1
Joint in our body -1Joint in our body -1
Joint in our body -1
 
Derivacion implicita
Derivacion implicitaDerivacion implicita
Derivacion implicita
 

Ähnlich wie [出張!雲勉 in Tokyo] Swagger で簡単APIドキュメント作成

Swagger jjug ccc 2018 spring
Swagger jjug ccc 2018 springSwagger jjug ccc 2018 spring
Swagger jjug ccc 2018 spring
kounan13
 
エンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJSエンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJS
Ayumi Goto
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!
Shinpei Ohtani
 

Ähnlich wie [出張!雲勉 in Tokyo] Swagger で簡単APIドキュメント作成 (20)

APIMeetup 20170329_ichimura
APIMeetup 20170329_ichimuraAPIMeetup 20170329_ichimura
APIMeetup 20170329_ichimura
 
OpenGLプログラミング
OpenGLプログラミングOpenGLプログラミング
OpenGLプログラミング
 
Swagger jjug ccc 2018 spring
Swagger jjug ccc 2018 springSwagger jjug ccc 2018 spring
Swagger jjug ccc 2018 spring
 
Swaggerを利用した新規サービス開発
Swaggerを利用した新規サービス開発Swaggerを利用した新規サービス開発
Swaggerを利用した新規サービス開発
 
JAWSDAYS2016 Technical Deep DIVE
JAWSDAYS2016 Technical Deep DIVE JAWSDAYS2016 Technical Deep DIVE
JAWSDAYS2016 Technical Deep DIVE
 
はてなのサービスの開発環境
はてなのサービスの開発環境はてなのサービスの開発環境
はてなのサービスの開発環境
 
クライアントサイドjavascript簡単紹介
クライアントサイドjavascript簡単紹介クライアントサイドjavascript簡単紹介
クライアントサイドjavascript簡単紹介
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入
 
初めてのPadrino
初めてのPadrino初めてのPadrino
初めてのPadrino
 
AWS SDK for Smalltalk
AWS SDK for SmalltalkAWS SDK for Smalltalk
AWS SDK for Smalltalk
 
2020/06/16 tsjp-azure-staticwebapps-vs_codespaces
2020/06/16 tsjp-azure-staticwebapps-vs_codespaces2020/06/16 tsjp-azure-staticwebapps-vs_codespaces
2020/06/16 tsjp-azure-staticwebapps-vs_codespaces
 
エンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJSエンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJS
 
企業におけるSpring@日本springユーザー会20090624
企業におけるSpring@日本springユーザー会20090624企業におけるSpring@日本springユーザー会20090624
企業におけるSpring@日本springユーザー会20090624
 
20160728 hyperscale #03
20160728 hyperscale #0320160728 hyperscale #03
20160728 hyperscale #03
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!
 
NTTコミュニケーションズ Cloudn勉強会資料 SDKでAPIをたたいてみよう
NTTコミュニケーションズ Cloudn勉強会資料 SDKでAPIをたたいてみようNTTコミュニケーションズ Cloudn勉強会資料 SDKでAPIをたたいてみよう
NTTコミュニケーションズ Cloudn勉強会資料 SDKでAPIをたたいてみよう
 
Adobe JSX入門
Adobe JSX入門Adobe JSX入門
Adobe JSX入門
 
JSDoc ToolKit
JSDoc ToolKitJSDoc ToolKit
JSDoc ToolKit
 
多分モダンなWebアプリ開発
多分モダンなWebアプリ開発多分モダンなWebアプリ開発
多分モダンなWebアプリ開発
 
アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門
 

[出張!雲勉 in Tokyo] Swagger で簡単APIドキュメント作成