LoginSignup
6
5

More than 5 years have passed since last update.

SwaggerでAPI仕様を書いてBluemix上のNode.jsで公開

Last updated at Posted at 2016-10-07

概要

SwaggerでAPIの仕様書を書いてIBM Bluemix上のNode.jsで公開するまでの手順です。

環境

Swagger Editor

インストール

install.sh
git clone https://github.com/swagger-api/swagger-editor.git
cd swagger-editor
npm install
npm start

注意点

  • Swagger Editorで書くと遅い、間違ったら固まる
    対策: エディタで書く → Swagger Editorにペーストして確認
  • HTML出力はバグがあるようでモデルの一部が出力されない?

IBM BluemixのNode.jsで公開

  • Swagger EditorからNode.jsに出力
  • package.jsonの修正
    • 必要に応じ、Licenseを修正
    • "cfenv": "*"を追加
package.json
{
  "name": "APIの名前",
  "version": "1.0.0",
  "description": "説明",
  "main": "index.js",
  "scripts": {
    "prestart": "npm install",
    "start": "node index.js"
  },
  "keywords": [
    "swagger"
  ],
  "license": "All Rights Reserved",
  "private": true,
  "dependencies": {
    "connect": "^3.2.0",
    "js-yaml": "^3.3.0",
    "swagger-tools": "0.10.1",
    "cfenv": "*"
  }
}
  • index.jsを修正
index.js
var cfenv = require( 'cfenv' );
var appEnv = cfenv.getAppEnv();
var serverPort = appEnv.port;

IBM Bluemixへ公開

bluemix.sh
bluemix api https://api.ng.bluemix.net
bluemix login -u email_address -o your_use_name _org -s dev
cf push "your_application_name"
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5