Home / Function/ compileSchemasForSerialization() — fastify Function Reference

compileSchemasForSerialization() — fastify Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8719dc54_f501_6906_b099_c680aa67f6e8["compileSchemasForSerialization()"]
  7c105413_01f0_7169_1c95_0f84d089bea5["validation.js"]
  8719dc54_f501_6906_b099_c680aa67f6e8 -->|defined in| 7c105413_01f0_7169_1c95_0f84d089bea5
  style 8719dc54_f501_6906_b099_c680aa67f6e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/validation.js lines 18–55

function compileSchemasForSerialization (context, compile) {
  if (!context.schema || !context.schema.response) {
    return
  }
  const { method, url } = context.config || {}
  context[responseSchema] = Object.keys(context.schema.response)
    .reduce(function (acc, statusCode) {
      const schema = context.schema.response[statusCode]
      statusCode = statusCode.toLowerCase()
      if (!scChecker.test(statusCode)) {
        throw new FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX()
      }

      if (schema.content) {
        const contentTypesSchemas = {}
        for (const mediaName of Object.keys(schema.content)) {
          const contentSchema = schema.content[mediaName].schema
          contentTypesSchemas[mediaName] = compile({
            schema: contentSchema,
            url,
            method,
            httpStatus: statusCode,
            contentType: mediaName
          })
        }
        acc[statusCode] = contentTypesSchemas
      } else {
        acc[statusCode] = compile({
          schema,
          url,
          method,
          httpStatus: statusCode
        })
      }

      return acc
    }, {})
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does compileSchemasForSerialization() do?
compileSchemasForSerialization() is a function in the fastify codebase, defined in lib/validation.js.
Where is compileSchemasForSerialization() defined?
compileSchemasForSerialization() is defined in lib/validation.js at line 18.

Analyze Your Own Codebase

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

Try Supermodel Free