@8select/serverless-plugin-api-docs 中文文档教程
serverless-plugin-api-docs
使用 < Serverless v1.0 的 href="https://swagger.io/docs/specification">SWAGGER 文档 项目。
一个 serverless 插件自动创建一个返回 swagger-ui HTML 基于给定的 swagger 规范 JSON 文件 GET /docs
=> 的 swagger-ui
Install
使用 npm
npm install --save-dev @8select/serverless-plugin-api-docs
:或 yarn
:
yarn add -D @8select/serverless-plugin-api-docs
将插件添加到您的 serverless.yml
文件:
plugins:
- serverless-plugin-api-docs
Prerequisites
下载 并托管 swagger-ui 库文件,例如使用 S3
- swagger-ui.css
- swagger-ui-bundle.js
- swagger-ui-standalone-preset.js
Configuration
custom:
documentation:
contentUrl: '<URL_TO_YOUR_HOSTED_SWAGGER_UI_FILES>' # REQUIRED
name: '<your_custom_lambda_function_name>' # OPTIONAL - default = 'docs'
要加载 swagger.json
,您需要添加 resolve.alias.
例如对于 webpack
:
假设:
<root>
|
|-docs - REST API swagger spec & definitions
| swagger.json
| webpack.config.json
module.exports = {
// [...],
resolve: {
alias: {
PATH_TO_SWAGGER_SPEC: path.resolve(__dirname, 'docs/swagger.json'),
},
},
// [...],
}
serverless-plugin-api-docs
Work with SWAGGER documentation for Serverless v1.0 projects.
A serverless plugin to automatically create a lambda function which returns the swagger-ui HTML based on the given swagger spec JSON file GET /docs
=> swagger-ui
Install
using npm
:
npm install --save-dev @8select/serverless-plugin-api-docs
or yarn
:
yarn add -D @8select/serverless-plugin-api-docs
Add the plugin to your serverless.yml
file:
plugins:
- serverless-plugin-api-docs
Prerequisites
Download and host swagger-ui library files e.g. with S3
- swagger-ui.css
- swagger-ui-bundle.js
- swagger-ui-standalone-preset.js
Configuration
custom:
documentation:
contentUrl: '<URL_TO_YOUR_HOSTED_SWAGGER_UI_FILES>' # REQUIRED
name: '<your_custom_lambda_function_name>' # OPTIONAL - default = 'docs'
To load your swagger.json
you need to add a resolve.alias
.
E.g. for webpack
:
Assupmtion:
<root>
|
|-docs - REST API swagger spec & definitions
| swagger.json
| webpack.config.json
module.exports = {
// [...],
resolve: {
alias: {
PATH_TO_SWAGGER_SPEC: path.resolve(__dirname, 'docs/swagger.json'),
},
},
// [...],
}