Skip to content

Commit

Permalink
hotfix: fix ValidationResult interface (#4045) (#4070)
Browse files Browse the repository at this point in the history
* fix: fix ValidationResult interface (#4045)

* docs(typescript): update src links

for types: ValidationResult, FastifyError

* test(types): update ValidationResult inteface test

- define object properties of ajv error object

* feat(types): update ValidationResult interface

- ValidationResult extends ajv's ErrorObject

* fix(types): fix ValidationResult interface

- replace ajv interface with plain properties
  • Loading branch information
alex-laz committed Jun 22, 2022
1 parent 1398d38 commit 81f28ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/Reference/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ A method for checking the existence of a type parser of a certain content type

##### fastify.FastifyError

[src](https://github.com/fastify/fastify/blob/main/types/error.d.ts#L17)
[src](https://github.com/fastify/fastify/blob/main/fastify.d.ts#L179)

FastifyError is a custom error object that includes status code and validation
results.
Expand All @@ -1369,7 +1369,7 @@ properties: `statusCode: number` and `validation: ValiationResult[]`.

##### fastify.ValidationResult

[src](https://github.com/fastify/fastify/blob/main/types/error.d.ts#L4)
[src](https://github.com/fastify/fastify/blob/main/fastify.d.ts#L184)

The route validation internally relies upon Ajv, which is a high-performance
JSON schema validator.
Expand Down
4 changes: 2 additions & 2 deletions fastify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ declare module '@fastify/error' {

export interface ValidationResult {
keyword: string;
dataPath: string;
instancePath: string;
schemaPath: string;
params: Record<string, string | string[]>;
message: string;
message?: string;
}

/* Export all additional types */
Expand Down
13 changes: 12 additions & 1 deletion test/types/fastify.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import fastify, {
LightMyRequestChain,
LightMyRequestResponse,
LightMyRequestCallback,
InjectOptions, FastifyBaseLogger
InjectOptions, FastifyBaseLogger,
ValidationResult
} from '../../fastify'
import { ErrorObject as AjvErrorObject } from 'ajv'
import * as http from 'http'
import * as https from 'https'
import * as http2 from 'http2'
Expand Down Expand Up @@ -208,3 +210,12 @@ fastify().then(fastifyInstance => expectAssignable<FastifyInstance>(fastifyInsta
expectAssignable<FastifyPluginAsync>(async () => {})
expectAssignable<FastifyPluginCallback>(() => {})
expectAssignable<FastifyPlugin>(() => {})

const ajvErrorObject: AjvErrorObject = {
keyword: '',
instancePath: '',
schemaPath: '',
params: {},
message: ''
}
expectAssignable<ValidationResult>(ajvErrorObject)

0 comments on commit 81f28ce

Please sign in to comment.