New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: type of validation function #4283
Changes from all commits
5a1fdb8
b483be5
1242235
48ced37
09575b0
0ac03cb
addb824
7cbc87e
da52e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { ErrorObject } from '@fastify/ajv-compiler' | ||
import { FastifyBaseLogger } from './logger' | ||
import { ContextConfigDefault, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault } from './utils' | ||
import { RouteGenericInterface } from './route' | ||
|
@@ -14,6 +15,11 @@ export interface RequestGenericInterface { | |
Headers?: RequestHeadersDefault; | ||
} | ||
|
||
export interface ValidationFunction { | ||
Eomm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(input: any): boolean | ||
errors?: null | ErrorObject[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we have also an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems to me that a separate issue with tests is needed here to account for this factor In any case, I will not be able to handle this case ( |
||
} | ||
|
||
/** | ||
* FastifyRequest is an instance of the standard http or http2 request objects. | ||
* It defaults to http.IncomingMessage, and it also extends the relative request object. | ||
|
@@ -61,9 +67,9 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou | |
readonly is404: boolean; | ||
readonly socket: RawRequest['socket']; | ||
|
||
getValidationFunction(httpPart: HTTPRequestPart): (input: any) => boolean | ||
getValidationFunction(schema: {[key: string]: any}): (input: any) => boolean | ||
compileValidationSchema(schema: {[key: string]: any}, httpPart?: HTTPRequestPart): (input: any) => boolean | ||
getValidationFunction(httpPart: HTTPRequestPart): ValidationFunction | ||
getValidationFunction(schema: {[key: string]: any}): ValidationFunction | ||
compileValidationSchema(schema: {[key: string]: any}, httpPart?: HTTPRequestPart): ValidationFunction | ||
validateInput(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean | ||
validateInput(input: any, httpPart?: HTTPRequestPart): boolean | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s add a small note just to indicate that this will only work this way of they’re using the default Fastify’s setup, if they’re tricking its own ValidationCompiler, most likely the behavior won’t be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you arrange the text, please?