Home / Function/ normalizeSchema() — fastify Function Reference

normalizeSchema() — fastify Function Reference

Architecture documentation for the normalizeSchema() function in schemas.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  babea439_85e8_6864_98a1_7766c86f4acd["normalizeSchema()"]
  e8bb6056_4217_c2ca_89f1_f68e8b759a9f["schemas.js"]
  babea439_85e8_6864_98a1_7766c86f4acd -->|defined in| e8bb6056_4217_c2ca_89f1_f68e8b759a9f
  c3b63201_965f_1f10_e72c_ffe00473f3cd["generateFluentSchema()"]
  babea439_85e8_6864_98a1_7766c86f4acd -->|calls| c3b63201_965f_1f10_e72c_ffe00473f3cd
  526a19f9_d6e4_e0b0_eddf_2e0838900330["isCustomSchemaPrototype()"]
  babea439_85e8_6864_98a1_7766c86f4acd -->|calls| 526a19f9_d6e4_e0b0_eddf_2e0838900330
  style babea439_85e8_6864_98a1_7766c86f4acd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/schemas.js lines 57–114

function normalizeSchema (routeSchemas, serverOptions) {
  if (routeSchemas[kSchemaVisited]) {
    return routeSchemas
  }

  // alias query to querystring schema
  if (routeSchemas.query) {
    // check if our schema has both querystring and query
    if (routeSchemas.querystring) {
      throw new FST_ERR_SCH_DUPLICATE('querystring')
    }
    routeSchemas.querystring = routeSchemas.query
  }

  generateFluentSchema(routeSchemas)

  for (const key of SCHEMAS_SOURCE) {
    const schema = routeSchemas[key]
    if (schema && !isCustomSchemaPrototype(schema)) {
      if (key === 'body' && schema.content) {
        const contentProperty = schema.content
        const keys = Object.keys(contentProperty)
        for (let i = 0; i < keys.length; i++) {
          const contentType = keys[i]
          const contentSchema = contentProperty[contentType].schema
          if (!contentSchema) {
            throw new FST_ERR_SCH_CONTENT_MISSING_SCHEMA(contentType)
          }
        }
        continue
      }
    }
  }

  if (routeSchemas.response) {
    const httpCodes = Object.keys(routeSchemas.response)
    for (const code of httpCodes) {
      if (isCustomSchemaPrototype(routeSchemas.response[code])) {
        continue
      }

      const contentProperty = routeSchemas.response[code].content

      if (contentProperty) {
        const keys = Object.keys(contentProperty)
        for (let i = 0; i < keys.length; i++) {
          const mediaName = keys[i]
          if (!contentProperty[mediaName].schema) {
            throw new FST_ERR_SCH_CONTENT_MISSING_SCHEMA(mediaName)
          }
        }
      }
    }
  }

  routeSchemas[kSchemaVisited] = true
  return routeSchemas
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does normalizeSchema() do?
normalizeSchema() is a function in the fastify codebase, defined in lib/schemas.js.
Where is normalizeSchema() defined?
normalizeSchema() is defined in lib/schemas.js at line 57.
What does normalizeSchema() call?
normalizeSchema() calls 2 function(s): generateFluentSchema, isCustomSchemaPrototype.

Analyze Your Own Codebase

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

Try Supermodel Free