LoginSignup
0
0

More than 5 years have passed since last update.

swagger スタブを立てる手順

Posted at

swagger-codegenの設定

$ git clone https://github.com/swagger-api/swagger-codegen
$ cd swagger-codegen
$ mvn clean package
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l nodejs-server \
-o samples/server/petstore/nodejs


自分の環境ではcloneに失敗してしまったため、以下のURLからzipファイルでダウンロードを行った。
Swagger Codegen 2.2.0
https://github.com/swagger-api/swagger-codegen/releases

APIを記述したyamlファイルを、swagger-codegen-2.2.0の直下に配置。
(今回はswagger.yamlを配置)

スタブサーバの生成

上記のコマンドを元に、実際に以下のコマンドを実行した。
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.yaml -l nodejs-server -o samples1/server
$ cd samples1/server
$ npm init
$ npm install
$ node index.js
Your server is listening on port 10010(http://localhost:10010)
Swagger-ui is available on http://localhost:10010/docs
http://localhost:10010/docs にアクセスし、何か文字を入れて、
[try it out!]ボタンを押下するとスタブのデータが出力される。

参考:
https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO#nodejs
https://news.mynavi.jp/itsearch/article/devsoft/2541

0
0
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
0
0