* 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)
| 9 | * @return {object}:a new SchemaController |
| 10 | */ |
| 11 | function 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 | |
| 40 | class SchemaController { |
| 41 | constructor (parent, options) { |
nothing calls this directly
no outgoing calls
no test coverage detected