Home / Function/ getSchemaSerializer() — fastify Function Reference

getSchemaSerializer() — fastify Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1c8fed08_fd33_4d3d_a1bf_b52b0e38c864["getSchemaSerializer()"]
  e8bb6056_4217_c2ca_89f1_f68e8b759a9f["schemas.js"]
  1c8fed08_fd33_4d3d_a1bf_b52b0e38c864 -->|defined in| e8bb6056_4217_c2ca_89f1_f68e8b759a9f
  style 1c8fed08_fd33_4d3d_a1bf_b52b0e38c864 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/schemas.js lines 144–201

function getSchemaSerializer (context, statusCode, contentType) {
  const responseSchemaDef = context[kSchemaResponse]
  if (!responseSchemaDef) {
    return false
  }
  if (responseSchemaDef[statusCode]) {
    if (responseSchemaDef[statusCode].constructor === Object && contentType) {
      const mediaName = contentType.split(';', 1)[0]
      if (responseSchemaDef[statusCode][mediaName]) {
        return responseSchemaDef[statusCode][mediaName]
      }

      // fallback to match all media-type
      if (responseSchemaDef[statusCode]['*/*']) {
        return responseSchemaDef[statusCode]['*/*']
      }

      return false
    }
    return responseSchemaDef[statusCode]
  }
  const fallbackStatusCode = (statusCode + '')[0] + 'xx'
  if (responseSchemaDef[fallbackStatusCode]) {
    if (responseSchemaDef[fallbackStatusCode].constructor === Object && contentType) {
      const mediaName = contentType.split(';', 1)[0]
      if (responseSchemaDef[fallbackStatusCode][mediaName]) {
        return responseSchemaDef[fallbackStatusCode][mediaName]
      }

      // fallback to match all media-type
      if (responseSchemaDef[fallbackStatusCode]['*/*']) {
        return responseSchemaDef[fallbackStatusCode]['*/*']
      }

      return false
    }

    return responseSchemaDef[fallbackStatusCode]
  }
  if (responseSchemaDef.default) {
    if (responseSchemaDef.default.constructor === Object && contentType) {
      const mediaName = contentType.split(';', 1)[0]
      if (responseSchemaDef.default[mediaName]) {
        return responseSchemaDef.default[mediaName]
      }

      // fallback to match all media-type
      if (responseSchemaDef.default['*/*']) {
        return responseSchemaDef.default['*/*']
      }

      return false
    }

    return responseSchemaDef.default
  }
  return false
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does getSchemaSerializer() do?
getSchemaSerializer() is a function in the fastify codebase, defined in lib/schemas.js.
Where is getSchemaSerializer() defined?
getSchemaSerializer() is defined in lib/schemas.js at line 144.

Analyze Your Own Codebase

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

Try Supermodel Free