Home / Function/ validate() — fastify Function Reference

validate() — fastify Function Reference

Architecture documentation for the validate() function in validation.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  208b6483_5f1a_738c_a527_eb1057e24926["validate()"]
  7c105413_01f0_7169_1c95_0f84d089bea5["validation.js"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|defined in| 7c105413_01f0_7169_1c95_0f84d089bea5
  545341d8_9015_b96b_9ecd_2827a3d3af7b["validateAsyncParams()"]
  545341d8_9015_b96b_9ecd_2827a3d3af7b -->|calls| 208b6483_5f1a_738c_a527_eb1057e24926
  6d4aac83_f8c0_6e8c_b745_4d690a27b537["validateAsyncBody()"]
  6d4aac83_f8c0_6e8c_b745_4d690a27b537 -->|calls| 208b6483_5f1a_738c_a527_eb1057e24926
  1b8b5462_a4ce_48ff_ab51_e79e338aab0e["validateAsyncQuery()"]
  1b8b5462_a4ce_48ff_ab51_e79e338aab0e -->|calls| 208b6483_5f1a_738c_a527_eb1057e24926
  4340bc1c_3ec7_7049_554d_4377b3a311e0["validateParam()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 4340bc1c_3ec7_7049_554d_4377b3a311e0
  15f5210f_0830_b915_ae26_16daa2ac22f1["wrapValidationError()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 15f5210f_0830_b915_ae26_16daa2ac22f1
  545341d8_9015_b96b_9ecd_2827a3d3af7b["validateAsyncParams()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 545341d8_9015_b96b_9ecd_2827a3d3af7b
  fe21b837_f8fe_01ab_7cf1_0abad23f07a7["getEssenceMediaType()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| fe21b837_f8fe_01ab_7cf1_0abad23f07a7
  6d4aac83_f8c0_6e8c_b745_4d690a27b537["validateAsyncBody()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 6d4aac83_f8c0_6e8c_b745_4d690a27b537
  1b8b5462_a4ce_48ff_ab51_e79e338aab0e["validateAsyncQuery()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 1b8b5462_a4ce_48ff_ab51_e79e338aab0e
  536b3a14_a627_c935_0aa3_740bafc7cf1e["validateAsyncHeaders()"]
  208b6483_5f1a_738c_a527_eb1057e24926 -->|calls| 536b3a14_a627_c935_0aa3_740bafc7cf1e
  style 208b6483_5f1a_738c_a527_eb1057e24926 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/validation.js lines 146–203

function validate (context, request, execution) {
  const runExecution = execution === undefined

  if (runExecution || !execution.skipParams) {
    const params = validateParam(context[paramsSchema], request, 'params')
    if (params) {
      if (typeof params.then !== 'function') {
        return wrapValidationError(params, 'params', context.schemaErrorFormatter)
      } else {
        return validateAsyncParams(params, context, request)
      }
    }
  }

  if (runExecution || !execution.skipBody) {
    let validatorFunction = null
    if (typeof context[bodySchema] === 'function') {
      validatorFunction = context[bodySchema]
    } else if (context[bodySchema]) {
      // TODO: add request.contentType and reuse it here
      const contentType = getEssenceMediaType(request.headers['content-type'])
      const contentSchema = context[bodySchema][contentType]
      if (contentSchema) {
        validatorFunction = contentSchema
      }
    }
    const body = validateParam(validatorFunction, request, 'body')
    if (body) {
      if (typeof body.then !== 'function') {
        return wrapValidationError(body, 'body', context.schemaErrorFormatter)
      } else {
        return validateAsyncBody(body, context, request)
      }
    }
  }

  if (runExecution || !execution.skipQuery) {
    const query = validateParam(context[querystringSchema], request, 'query')
    if (query) {
      if (typeof query.then !== 'function') {
        return wrapValidationError(query, 'querystring', context.schemaErrorFormatter)
      } else {
        return validateAsyncQuery(query, context, request)
      }
    }
  }

  const headers = validateParam(context[headersSchema], request, 'headers')
  if (headers) {
    if (typeof headers.then !== 'function') {
      return wrapValidationError(headers, 'headers', context.schemaErrorFormatter)
    } else {
      return validateAsyncHeaders(headers, context, request)
    }
  }

  return false
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does validate() do?
validate() is a function in the fastify codebase, defined in lib/validation.js.
Where is validate() defined?
validate() is defined in lib/validation.js at line 146.
What does validate() call?
validate() calls 7 function(s): getEssenceMediaType, validateAsyncBody, validateAsyncHeaders, validateAsyncParams, validateAsyncQuery, validateParam, wrapValidationError.
What calls validate()?
validate() is called by 3 function(s): validateAsyncBody, validateAsyncParams, validateAsyncQuery.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free