[英]How can we make the swagger-js library save web service interface definitions?
We are writing an Angular web application that uses the swagger-js library (version 2.1.25) to call RESTful web services described with Swagger 2.0. 我们正在编写一个Angular Web应用程序,它使用swagger-js库(版本2.1.25)来调用Swagger 2.0描述的RESTful Web服务。
Each time we call a service, we create a new Swagger client object, so the swagger-js library requests the Swagger interface definition again (see pseudo-code of our calls below). 每次调用服务时,我们都会创建一个新的Swagger客户端对象,因此swagger-js库会再次请求Swagger接口定义(请参阅下面的调用伪代码)。 The JSON definitions for our services can be quite large, on the order of 40 to 120 K bytes.
我们服务的JSON定义可能非常大,大约40到120 K字节。 As far as we can tell, we can't reuse the Swagger client objects
据我们所知,我们无法重用Swagger客户端对象
Is there a way to get the swagger-js library to cache the Swagger interface definitions for web services, or reuse the client objects, so that we don't waste bandwidth downloading interface definitions over and over ? 有没有办法让swagger-js库缓存Web服务的Swagger接口定义,或重用客户端对象,这样我们就不会浪费带宽下载接口定义一遍又一遍 ?
Sample code below to GET data from the serviceURL/foo entry point in a RESTful service. 以下示例代码从RESTful服务中的serviceURL / foo入口点获取数据。
var swagger = new SwaggerClient({
url: "serviceURL",
success: () => {
swagger.foo.fooGet({param1: x, param2: y},
(results) => {
if ( /* results good */ ) { /* do things with results */ }
else { /* report bad results */ }
}
}, (errorResponse) => {
/* alert user that call failed */
});
});
我们最终在我们的Angular应用程序中保留了长期存在的SwaggerClient对象,用于我们经常调用的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.