简体   繁体   English

我们如何让swagger-js库保存Web服务接口定义?

[英]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.

相关问题 如何使用swagger-js生成静态HTML文档? - How to generate static HTML documentation with swagger-js? 如何将多个授权密钥传递给swagger-js? - How to pass multiple authorization keys to swagger-js? 如何期望和接收 404 作为 swagger-api/swagger-js 中的正常响应,而不是错误 - How to expect and receive 404 as normal response in swagger-api/swagger-js, not an error 如何在swagger-js客户端中为需要同时有formData和path参数的PUT请求设置数据? - How to properly set the data in swagger-js client for a PUT request which requires BOTH formData and path parameters? 我们如何在js中识别Dynamics CRM Web api版本? - How can we identify the Dynamics CRM web api version in js? 如何将ts类型定义与npm js库捆绑在一起 - How to bundle ts types definitions with npm js library 如何使用Breeze JS进行简单的Web服务调用 - How to make a simple web service call using Breeze JS 如何在Web Worker中使用emscripted .js库 - How can I use an emscripted .js library in a Web Worker 如何使用DefinitelyTyped接口定义获得WebStorm的JavaScript库支持? - How do I get WebStorm's JavaScript Library support using DefinitelyTyped interface definitions to work? 我可以制作一个我可以在CSS,JS和HTML之间共享的自定义颜色定义吗? - Can I make a custom colour definitions that I can share between CSS, JS and HTML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM