Home / Class/ SchemaController Class — fastify Architecture

SchemaController Class — fastify Architecture

Architecture documentation for the SchemaController class in schema-controller.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  f9c71bed_770a_87b0_8d4c_3279f23ba910["SchemaController"]
  a2112e8b_4082_af50_d135_2032dc6e6889["schema-controller.js"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|defined in| a2112e8b_4082_af50_d135_2032dc6e6889
  a7046e65_7261_6c90_8b9c_c3e8c78b392c["constructor()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| a7046e65_7261_6c90_8b9c_c3e8c78b392c
  c776ff3f_d0ac_b112_3203_9f5f65ddc1ff["add()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| c776ff3f_d0ac_b112_3203_9f5f65ddc1ff
  6d5eebf9_b243_4e51_7083_9529e1f6d714["getSchema()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 6d5eebf9_b243_4e51_7083_9529e1f6d714
  642d13d0_7bf1_b585_07fd_8a26f40d47af["getSchemas()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 642d13d0_7bf1_b585_07fd_8a26f40d47af
  6d12cc56_c152_f74b_d8a6_1702f23f0b36["setValidatorCompiler()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 6d12cc56_c152_f74b_d8a6_1702f23f0b36
  fd251ae9_58ce_22a7_c9ee_7377175ded44["setSerializerCompiler()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| fd251ae9_58ce_22a7_c9ee_7377175ded44
  25b7e42f_ca16_2322_a136_265dced12160["getValidatorCompiler()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 25b7e42f_ca16_2322_a136_265dced12160
  1c0c7d20_50bc_9fd7_04c9_9664f0882946["getSerializerCompiler()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 1c0c7d20_50bc_9fd7_04c9_9664f0882946
  ebf1979f_97f8_6239_dcf3_bb6c55893f02["getSerializerBuilder()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| ebf1979f_97f8_6239_dcf3_bb6c55893f02
  c7a5646b_0496_fa0a_7c56_e6356de06195["getValidatorBuilder()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| c7a5646b_0496_fa0a_7c56_e6356de06195
  974acc41_e7e9_a81f_8cb8_7d2ba90fa437["setupValidator()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 974acc41_e7e9_a81f_8cb8_7d2ba90fa437
  31908b4d_8655_0761_7213_2e64f81d6951["setupSerializer()"]
  f9c71bed_770a_87b0_8d4c_3279f23ba910 -->|method| 31908b4d_8655_0761_7213_2e64f81d6951

Relationship Graph

Source Code

lib/schema-controller.js lines 40–161

class SchemaController {
  constructor (parent, options) {
    this.opts = options || parent?.opts
    this.addedSchemas = false

    this.compilersFactory = this.opts.compilersFactory

    if (parent) {
      this.schemaBucket = this.opts.bucket(parent.getSchemas())
      this.validatorCompiler = parent.getValidatorCompiler()
      this.serializerCompiler = parent.getSerializerCompiler()
      this.isCustomValidatorCompiler = parent.isCustomValidatorCompiler
      this.isCustomSerializerCompiler = parent.isCustomSerializerCompiler
      this.parent = parent
    } else {
      this.schemaBucket = this.opts.bucket()
      this.isCustomValidatorCompiler = this.opts.isCustomValidatorCompiler || false
      this.isCustomSerializerCompiler = this.opts.isCustomSerializerCompiler || false
    }
  }

  // Bucket interface
  add (schema) {
    this.addedSchemas = true
    return this.schemaBucket.add(schema)
  }

  getSchema (schemaId) {
    return this.schemaBucket.getSchema(schemaId)
  }

  getSchemas () {
    return this.schemaBucket.getSchemas()
  }

  setValidatorCompiler (validatorCompiler) {
    // Set up as if the fixed validator compiler had been provided
    // by a custom 'options.compilersFactory.buildValidator' that
    // always returns the same compiler object. This is required because:
    //
    // - setValidatorCompiler must immediately install a compiler to preserve
    //   legacy behavior
    // - setupValidator will recreate compilers from builders in some
    //   circumstances, so we have to install this adapter to make it
    //   behave the same if the legacy API is used
    //
    // The cloning of the compilersFactory object is necessary because
    // we are aliasing the parent compilersFactory if none was provided
    // to us (see constructor.)
    this.compilersFactory = Object.assign(
      {},
      this.compilersFactory,
      { buildValidator: () => validatorCompiler })
    this.validatorCompiler = validatorCompiler
    this.isCustomValidatorCompiler = true
  }

  setSerializerCompiler (serializerCompiler) {
    // Set up as if the fixed serializer compiler had been provided
    // by a custom 'options.compilersFactory.buildSerializer' that
    // always returns the same compiler object. This is required because:
    //
    // - setSerializerCompiler must immediately install a compiler to preserve
    //   legacy behavior
    // - setupSerializer will recreate compilers from builders in some
    //   circumstances, so we have to install this adapter to make it
    //   behave the same if the legacy API is used
    //
    // The cloning of the compilersFactory object is necessary because
    // we are aliasing the parent compilersFactory if none was provided
    // to us (see constructor.)
    this.compilersFactory = Object.assign(
      {},
      this.compilersFactory,
      { buildSerializer: () => serializerCompiler })
    this.serializerCompiler = serializerCompiler
    this.isCustomSerializerCompiler = true
  }

  getValidatorCompiler () {
    return this.validatorCompiler || (this.parent && this.parent.getValidatorCompiler())

Frequently Asked Questions

What is the SchemaController class?
SchemaController is a class in the fastify codebase, defined in lib/schema-controller.js.
Where is SchemaController defined?
SchemaController is defined in lib/schema-controller.js at line 40.

Analyze Your Own Codebase

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

Try Supermodel Free