|
1 | 1 | /* eslint-disable @typescript-eslint/no-floating-promises */ |
2 | 2 |
|
3 | 3 | import Ajv from 'ajv' |
| 4 | +import addFormats from 'ajv-formats' |
4 | 5 | import fastify, { FastifyInstance, FastifyPluginOptions, FastifyReply, FastifyRequest, ValidationResult } from 'fastify' |
5 | 6 | import { ACCEPTED, INTERNAL_SERVER_ERROR, OK } from 'http-errors-enhanced' |
6 | 7 | import t from 'tap' |
@@ -146,20 +147,27 @@ t.test('Validation', (t: Test) => { |
146 | 147 | useDefaults: true, |
147 | 148 | coerceTypes: true, |
148 | 149 | allErrors: true, |
149 | | - nullable: true, |
150 | 150 | formats: { |
151 | | - invalidResponseCode(raw: number): boolean { |
152 | | - return raw < 100 && raw > 599 |
| 151 | + invalidResponseCode: { |
| 152 | + validate(raw: number): boolean { |
| 153 | + return raw < 100 && raw > 599 |
| 154 | + } |
153 | 155 | }, |
154 | | - invalidResponse(raw: number): boolean { |
155 | | - return raw < 100 && raw > 599 |
| 156 | + invalidResponse: { |
| 157 | + validate(raw: number): boolean { |
| 158 | + return raw < 100 && raw > 599 |
| 159 | + } |
156 | 160 | }, |
157 | | - noMessage(): boolean { |
158 | | - return false |
| 161 | + noMessage: { |
| 162 | + validate(): boolean { |
| 163 | + return false |
| 164 | + } |
159 | 165 | } |
160 | 166 | } |
161 | 167 | }) |
162 | 168 |
|
| 169 | + addFormats(ajv) |
| 170 | + |
163 | 171 | const schema = { |
164 | 172 | type: 'object', |
165 | 173 | properties: { |
@@ -225,7 +233,7 @@ t.test('Validation', (t: Test) => { |
225 | 233 | }, |
226 | 234 | pattern: { |
227 | 235 | type: 'string', |
228 | | - pattern: '\\d+{a}abc' |
| 236 | + pattern: '\\d+\\{a\\}abc' |
229 | 237 | }, |
230 | 238 | uuid: { |
231 | 239 | type: 'string', |
@@ -337,17 +345,17 @@ t.test('Validation', (t: Test) => { |
337 | 345 | emptyArray: 'must be a empty array', |
338 | 346 | minItems: 'must be an array with at least 2 items', |
339 | 347 | maxItems: 'must be an array with at most 2 items', |
340 | | - 'arrayPath.0': 'must be a valid number', |
341 | | - "objectPath.'x-abc'": 'must be a valid number', |
342 | | - 'objectPath.cde': 'must be a valid number', |
| 348 | + 'arrayPath/0': 'must be a valid number', |
| 349 | + 'objectPath/x-abc': 'must be a valid number', |
| 350 | + 'objectPath/cde': 'must be a valid number', |
343 | 351 | minimum: 'must be a number greater than or equal to 5', |
344 | 352 | maximum: 'must be a number less than or equal to 5', |
345 | 353 | integer: 'must be a valid integer number', |
346 | 354 | object: 'must be a object', |
347 | 355 | number: 'must be a valid number', |
348 | 356 | enum: 'must be one of the following values: "a", "b" or "c"', |
349 | 357 | presentString: 'must be a non empty string', |
350 | | - pattern: 'must match pattern "\\d+{a}abc"', |
| 358 | + pattern: 'must match pattern "\\d+\\{a\\}abc"', |
351 | 359 | uuid: 'must be a valid GUID (UUID v4)', |
352 | 360 | hostname: 'must be a valid hostname', |
353 | 361 | ipv4: 'must be a valid IPv4', |
|
0 commit comments