Redocを使ってみた
概要
- 最近Redocを使用したAPI Documentationを見かけたので、触ってみた
使い方
用意するものは
- 表示用のHTML
- swagger.yaml
の2つだけです!
swagger.yamlの書き方はここでは触れませんが、
ここでは以下のものを使用します!
swagger.yaml
swagger: "2.0"
info:
description: "Redocサンプル"
title: "Redoc sample"
version: "1.0.0"
paths:
/user:
get:
summary: "ユーザ検索"
parameters:
- name: userId
in: query
description : 検索したいユーザのID
type: "string"
responses:
200:
description: "成功時のレスポンス"
HTMLを作成してみます
表示用のHTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redoc Sample</title>
</head>
<body>
<redoc spec-url="./swagger.yaml"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
</body>
</html>
ポイントは2つだけ!
- CDNからredoc.standalone.jsを読み込む
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js">
- redocタグでswagger.yamlを指定する
<redoc spec-url="./swagger.yaml"></redoc>
ブラウザで表示してみると…
シングルページにしたいな…
redoc-cliを使えばOK!
# cliをインストール
$ npm i -g redoc-cli
# index.htmlとredoc.standalone.jsとswagger.yamlをひとまとめにしたHTMLを生成(するイメージ)
$ redoc-cli bundle swagger.yaml
これでredoc-static.html
が生成されます!
Author And Source
この問題について(Redocを使ってみた), 我々は、より多くの情報をここで見つけました https://qiita.com/rhirabay/items/59c134aa052dbc4b982b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .