strongloop,如何为自定义端点定义响应类 [英] strongloop, how to define a response class for a custom endpoint

查看:34
本文介绍了strongloop,如何为自定义端点定义响应类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,您可以创建自定义响应类;https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions

According to the documentation you can create custom response classes; https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions

我使用的远程方法描述是:

The remote method description I use is:

common/models/products-sku.js

common/models/products-sku.js

ProductsSku.remoteMethod('getSomeData',{http: {path: '/getSomeData', 动词: 'get'},接受: {arg: 'filter', type: 'object', http: { source: 'query'} },返回:{arg: 'id',描述:'自定义端点',类型:'自定义产品类型',根:真的}});

在同一个文件中,我定义了 CustomProductType;

In the same file I have a definition for the CustomProductType;

var CustomProductType: {身份证号码,名称:字符串,...};

现在,如果我打开资源管理器,响应类被定义为 CustomProductType 但/explorer/resources/ProductsSku swagger 定义中没有模型定义(这仍然是 1.2)

Now if I open the explorer the response class is defined as CustomProductType but there is no model definition in the /explorer/resources/ProductsSku swagger definition (this is still swagger 1.2)

由于这不是一个实际的模型,我如何注册/定义模型,以便它与 api 定义一起发送.

As this is not an actual model, how do i register/define the model, such that it is send with the api definition.

==我尝试过的:

common/models/products-sku.js:

common/models/products-sku.js:

var DataSource = require('loopback-datasource-juggler').DataSource;var ds = new DataSource('memory');ds.define('CustomProductType', CustomProductType);

内存数据源是因为它不是实际的模型.

The memory datasource is because it is not an actual Model.

推荐答案

由于这不在文档中,所以这是我所做的.

As this is not in the documentation, here is what I did.

在remoteMethod定义中加入你喜欢的响应类名称正如我在上面对 type: 'CustomProductType'

Add the name of the response class you like to the remoteMethod definition as I did above with the type: 'CustomProductType'

转到 server/model-config.json 文件并在那里添加类型

Go to the server/model-config.json file and add the type there

自定义产品类型":{数据源":假,公开":真实}

现在将您的模型定义添加到 common/models/custom_product_type.json

now add your model definition to the common/models/custom_product_type.json

这篇关于strongloop,如何为自定义端点定义响应类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆