UNPKG

swagger-tests

Version:

A typescript framework for testing an api against a swagger 3.0 json file.

52 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const components_1 = require("./swagger/components"); const info_1 = require("./swagger/info"); const server_1 = require("./swagger/server"); const underscore_1 = require("underscore"); const fs_1 = require("fs"); class SwaggerApi { constructor() { this.testedOperations = []; this.create(underscore_1.extend(this, this.json())); } create(api) { api.components = underscore_1.extend(new components_1.SwaggerComponents(), api.components); api.info = underscore_1.extend(new info_1.SwaggerInfo(), api.info); api.servers = api.servers.map((server) => { return underscore_1.extend(new server_1.SwaggerServer(), server); }); return api; } json() { return JSON.parse(fs_1.readFileSync('api.json', 'utf8')); } routes() { return Object.keys(this.paths); } routeOperations(route) { return Object.keys(this.paths[route]); } routeOperationResponses(route, operation) { return Object.keys(this.paths[route][operation].responses); } operationResponses() { let ids = []; this.routes().map((route) => { return this.routeOperations(route).map((operation) => { this.routeOperationResponses(route, operation).map((statusCode) => { ids.push(`${route}#${operation}::${statusCode}`); }); }); }); return ids; } setTestedOperation(operation) { this.testedOperations.push(operation); } getTestedOperations() { return this.testedOperations; } } exports.SwaggerApi = SwaggerApi; //# sourceMappingURL=api.js.map