Swagger-based jQuery Ajax Validation
Yahya M. Tashtoush, Mohammed Nour Al-Rashdan, Osama Salameh, Mohammad A. Alsmirat · 2019
JavaScript is a vital programming language for web applications and it is becoming more important as it is being adopted for developing mobile and desktop applications. Many JavaScript applications are making use of Ajax requests to communicate with remote servers to fulfill its intended purpose. The use of Ajax requests in JavaScript results in two main issues, traditional type checking in other programming languages is not available in JavaScript and JavaScript application does not know what APIs the remote server serves. In this paper, we will introduce a novel tool called Ajax Validator to solve some of the consequences of the mentioned issues. We will use Swagger to validate Ajax requests against their specifications in terms of Local Ajax HTTP Method and Body consistency, Local Ajax HTTP Method and Remote HTTP Method consistency, and Local and Remote HTTP Headers consistency. To evaluate our tool, we obtained 666 swagger specifications for different API providers using the GURU project and nine JavaScript applications from GitHub. From the nine JavaScript Applications, our results showed that eight applications were locally consistent, and one was not. Five applications were remotely consistent, one was not and three of them were not applicable to the validator checking, due to syntax errors or non-matching paths in the Swagger specification. Regarding the header validation, one application was missing two headers in one of its Ajax requests that were specified in the Swagger specification. Also, the same Ajax request specified three headers that were not expected by the Swagger specification. Allowing IDEs to have such Ajax requests checking capabilities in static time will help in reducing the testing costs as long as reducing the runtime errors that a developer could face and fix.