MCPcopy Create free account
hub / github.com/fastify/fastify / buildSchemaController

Function buildSchemaController

lib/schema-controller.js:11–38  ·  view source on GitHub ↗

* Called at every fastify context that is being created. * @param {object} parentSchemaCtrl: the SchemaController instance of the Fastify parent context * @param {object} opts: the `schemaController` server option. It can be undefined when a parentSchemaCtrl is set * @return {object}:a new Schema

(parentSchemaCtrl, opts)

Source from the content-addressed store, hash-verified

9 * @return {object}:a new SchemaController
10 */
11function buildSchemaController (parentSchemaCtrl, opts) {
12 if (parentSchemaCtrl) {
13 return new SchemaController(parentSchemaCtrl, opts)
14 }
15
16 const compilersFactory = Object.assign({
17 buildValidator: null,
18 buildSerializer: null
19 }, opts?.compilersFactory)
20
21 if (!compilersFactory.buildValidator) {
22 const ValidatorSelector = require('@fastify/ajv-compiler')
23 compilersFactory.buildValidator = ValidatorSelector()
24 }
25 if (!compilersFactory.buildSerializer) {
26 const SerializerSelector = require('@fastify/fast-json-stringify-compiler')
27 compilersFactory.buildSerializer = SerializerSelector()
28 }
29
30 const option = {
31 bucket: (opts && opts.bucket) || buildSchemas,
32 compilersFactory,
33 isCustomValidatorCompiler: typeof opts?.compilersFactory?.buildValidator === 'function',
34 isCustomSerializerCompiler: typeof opts?.compilersFactory?.buildSerializer === 'function'
35 }
36
37 return new SchemaController(undefined, option)
38}
39
40class SchemaController {
41 constructor (parent, options) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected