strongloop,如何为自定义端点定义响应 class
strongloop, how to define a response class for a custom endpoint
根据文档,您可以创建自定义响应 classes;
https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions
我使用的远程方法描述是:
common/models/products-sku.js
ProductsSku.remoteMethod(
'getSomeData',
{
http: {path: '/getSomeData', verb: 'get'},
accepts: {arg: 'filter', type: 'object', http: { source: 'query'} },
returns: {
arg: 'id',
description: 'Custom endpoint',
type: 'CustomProductType',
root: true
}
}
);
在同一个文件中,我有 CustomProductType 的定义;
var CustomProductType: {
id: Number,
name: String,
...
};
现在,如果我打开资源管理器,响应 class 被定义为 CustomProductType 但 /explorer/resources/ProductsSku swagger 定义中没有模型定义(这仍然是 swagger 1.2)
由于这不是实际模型,我如何 register/define 模型,以便它与 api 定义一起发送。
==
我尝试过的:
common/models/products-sku.js:
var DataSource = require('loopback-datasource-juggler').DataSource;
var ds = new DataSource('memory');
ds.define('CustomProductType', CustomProductType);
内存数据源是因为它不是实际模型。
因为这不在文档中,所以这是我所做的。
将您喜欢的响应名称添加到 remoteMethod 定义中 class
正如我在上面对 type: 'CustomProductType'
所做的那样
转到 server/model-config.json 文件并在其中添加类型
"CustomProductType": {
"dataSource": false,
"public": true
}
现在将您的模型定义添加到 common/models/custom_product_type.json
根据文档,您可以创建自定义响应 classes; https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions
我使用的远程方法描述是:
common/models/products-sku.js
ProductsSku.remoteMethod(
'getSomeData',
{
http: {path: '/getSomeData', verb: 'get'},
accepts: {arg: 'filter', type: 'object', http: { source: 'query'} },
returns: {
arg: 'id',
description: 'Custom endpoint',
type: 'CustomProductType',
root: true
}
}
);
在同一个文件中,我有 CustomProductType 的定义;
var CustomProductType: {
id: Number,
name: String,
...
};
现在,如果我打开资源管理器,响应 class 被定义为 CustomProductType 但 /explorer/resources/ProductsSku swagger 定义中没有模型定义(这仍然是 swagger 1.2)
由于这不是实际模型,我如何 register/define 模型,以便它与 api 定义一起发送。
== 我尝试过的:
common/models/products-sku.js:
var DataSource = require('loopback-datasource-juggler').DataSource;
var ds = new DataSource('memory');
ds.define('CustomProductType', CustomProductType);
内存数据源是因为它不是实际模型。
因为这不在文档中,所以这是我所做的。
将您喜欢的响应名称添加到 remoteMethod 定义中 class
正如我在上面对 type: 'CustomProductType'
转到 server/model-config.json 文件并在其中添加类型
"CustomProductType": {
"dataSource": false,
"public": true
}
现在将您的模型定义添加到 common/models/custom_product_type.json