@4geit/swg-product-model 中文文档教程
@4geit/swg-product-model
产品模型和端点
Installation
- A recommended way to install @4geit/swg-product-model is through npm package manager using the following command:
npm i @4geit/swg-product-model --save
或者使用 yarn
使用以下命令:
yarn add @4geit/swg-product-model
- In your swagger file, you need to add a reference to the
SwgProductModel
definition under thedefinitions
property (e.g./api/swagger/swagger.yaml
) as below:
swagger: "2.0"
# ...
definitions:
SwgProductModel:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/SwgProductModel
# ...
- SwgProductModel also comes along with some endpoints you can expose to the API, to do so you will need to add a reference to the
SwgProductModel
definition under thepaths
property (e.g./api/swagger/swagger.yaml
) as below:
swagger: "2.0"
# ...
paths:
/product:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/ProductListPath
/product/{id}:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/ProductItemPath
/product/populate:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/PopulatePath
# ...
您还需要将路径添加到 swg-product-model< 的
controllers
文件夹/code> 包,这样 swagger-node 就会找到相关的控制器来使用。 编辑文件 /config/default.yaml
并向属性 mockControllersDirs
和 controllersDirs
添加两个新路径,如下所示:
swagger:
# ...
bagpipes:
_router:
# ...
mockControllersDirs:
# ...
- node_modules/@4geit/swg-product-model/mocks
# ...
controllersDirs:
# ...
- node_modules/@4geit/swg-product-model/controllers
# ...
@4geit/swg-product-model
product model and endpoints
Installation
- A recommended way to install @4geit/swg-product-model is through npm package manager using the following command:
npm i @4geit/swg-product-model --save
Or use yarn
using the following command:
yarn add @4geit/swg-product-model
- In your swagger file, you need to add a reference to the
SwgProductModel
definition under thedefinitions
property (e.g./api/swagger/swagger.yaml
) as below:
swagger: "2.0"
# ...
definitions:
SwgProductModel:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/SwgProductModel
# ...
- SwgProductModel also comes along with some endpoints you can expose to the API, to do so you will need to add a reference to the
SwgProductModel
definition under thepaths
property (e.g./api/swagger/swagger.yaml
) as below:
swagger: "2.0"
# ...
paths:
/product:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/ProductListPath
/product/{id}:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/ProductItemPath
/product/populate:
$ref: ../../node_modules/@4geit/swg-product-model/swagger.yaml#/definitions/PopulatePath
# ...
And you will also need to add the path to the controllers
folder of the swg-product-model
package so that swagger-node will find the relevant controller to use. Edit the file /config/default.yaml
and add two new paths to the properties mockControllersDirs
and controllersDirs
as illustrated below:
swagger:
# ...
bagpipes:
_router:
# ...
mockControllersDirs:
# ...
- node_modules/@4geit/swg-product-model/mocks
# ...
controllersDirs:
# ...
- node_modules/@4geit/swg-product-model/controllers
# ...