MCPcopy
hub / github.com/fastify/fastify / validate

Function validate

lib/validation.js:146–201  ·  view source on GitHub ↗
(context, request, execution)

Source from the content-addressed store, hash-verified

144}
145
146function validate (context, request, execution) {
147 const runExecution = execution === undefined
148
149 if (runExecution || !execution.skipParams) {
150 const params = validateParam(context[paramsSchema], request, 'params')
151 if (params) {
152 if (typeof params.then !== 'function') {
153 return wrapValidationError(params, 'params', context.schemaErrorFormatter)
154 } else {
155 return validateAsyncParams(params, context, request)
156 }
157 }
158 }
159
160 if (runExecution || !execution.skipBody) {
161 let validatorFunction = null
162 if (typeof context[bodySchema] === 'function') {
163 validatorFunction = context[bodySchema]
164 } else if (context[bodySchema]) {
165 const contentSchema = context[bodySchema][request.mediaType]
166 if (contentSchema) {
167 validatorFunction = contentSchema
168 }
169 }
170 const body = validateParam(validatorFunction, request, 'body')
171 if (body) {
172 if (typeof body.then !== 'function') {
173 return wrapValidationError(body, 'body', context.schemaErrorFormatter)
174 } else {
175 return validateAsyncBody(body, context, request)
176 }
177 }
178 }
179
180 if (runExecution || !execution.skipQuery) {
181 const query = validateParam(context[querystringSchema], request, 'query')
182 if (query) {
183 if (typeof query.then !== 'function') {
184 return wrapValidationError(query, 'querystring', context.schemaErrorFormatter)
185 } else {
186 return validateAsyncQuery(query, context, request)
187 }
188 }
189 }
190
191 const headers = validateParam(context[headersSchema], request, 'headers')
192 if (headers) {
193 if (typeof headers.then !== 'function') {
194 return wrapValidationError(headers, 'headers', context.schemaErrorFormatter)
195 } else {
196 return validateAsyncHeaders(headers, context, request)
197 }
198 }
199
200 return false
201}
202
203function validateAsyncParams (validatePromise, context, request) {

Callers 5

validateAsyncParamsFunction · 0.70
validateAsyncBodyFunction · 0.70
validateAsyncQueryFunction · 0.70
validateInitialConfigFunction · 0.70
request.jsFile · 0.70

Calls 6

validateParamFunction · 0.85
wrapValidationErrorFunction · 0.85
validateAsyncParamsFunction · 0.85
validateAsyncBodyFunction · 0.85
validateAsyncQueryFunction · 0.85
validateAsyncHeadersFunction · 0.85

Tested by

no test coverage detected