-
Notifications
You must be signed in to change notification settings - Fork 476
/
verifyPath.ts
39 lines (32 loc) · 1.39 KB
/
verifyPath.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {Swagger} from '../../../src/swagger/swagger';
import * as chai from 'chai';
const expect = chai.expect;
export const modelName = '#/definitions/TestModel';
export function VerifyPath(
spec: Swagger.Spec,
route: string,
getOperation: (path: Swagger.Path) => Swagger.Operation,
isCollection?: boolean,
isNoContent?: boolean
) {
const path = spec.paths[route];
expect(path, `Path object for ${route} route wasn\'t generated.`).to.exist;
const operation = getOperation(path);
expect(operation, `Method for ${route} route wasn\'t generated.`).to.exist;
expect(operation.responses, `Response object for ${route} route wasn\'t generated.`).to.exist;
if (isNoContent) {
const successResponse = operation.responses['204'];
expect(successResponse, `204 response for ${route} route wasn\'t generated.`).to.exist;
return path;
}
const successResponse = operation.responses['200'];
expect(successResponse, `200 response for ${route} route wasn\'t generated.`).to.exist;
expect(successResponse.schema, `Schema for 200 response ${route} route wasn\'t generated.`).to.exist;
if (isCollection) {
expect(successResponse.schema.type).to.equal('array');
expect((successResponse.schema.items as any).$ref).to.equal(modelName);
} else {
expect(successResponse.schema.$ref).to.equal(modelName);
}
return path;
}