This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtypings.d.ts
92 lines (86 loc) · 2.2 KB
/
typings.d.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
declare module 'gavel' {
export enum RESTMethods {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
PATCH = 'PATCH',
DELETE = 'DELETE',
OPTIONS = 'OPTIONS'
}
export interface HTTPMessage {
method: RESTMethods;
uri: string;
statusCode: string | number;
headers: Record<string, string> | string;
body: Record<string, any> | string;
/**
* Instance of the supported version of [JSON Schema](https://json-schema.org/).
*/
bodySchema: Record<string, any> | string;
}
export enum FieldKind {
text = 'text',
json = 'json'
}
export interface ValidationResult {
/**
* Indicates whether the actual HTTP message is valid
* against the expected HTTP message.
*/
valid: boolean;
/**
* Validation results of each individual HTTP message
* field (i.e. `statusCode`, `body`, etc).
*/
fields: Record<string, FieldValidationResult>;
}
export interface FieldValidationResult {
/**
* Indicates whether a single HTTP message field is valid.
*/
valid: boolean;
/**
* Kind of validation that has been applied to the field.
*/
kind: FieldKind | null;
/**
* Normalized HTTP message field values that are being validated.
*/
values: {
expected: any;
actual: any;
};
/**
* The list of validation errors, if any.
*/
errors: FieldValidationError[];
}
export interface FieldValidationError {
message: string;
/**
* Arbitrary information about the validation error.
* Dependends on the HTTP message field's "kind" property.
*/
location?: {
/**
* A complete JSON pointer to the related property in the data.
*/
pointer?: string;
property?: string[];
/**
* A JSON pointer to the relevant rule in the JSON Schema.
* Applicable only if validating using `bodySchema` in
* the expected HTTP message.
*/
schemaPath?: string;
};
}
/**
* Validates a given expected HTTP message against
* the actual HTTP message.
*/
export function validate(
expectedMessage: Partial<HTTPMessage>,
actualMessage: Partial<HTTPMessage>
): ValidationResult;
}