schemas.js — fastify Source File
Architecture documentation for schemas.js, a javascript file in the fastify codebase.
Entity Profile
Relationship Graph
Source Code
'use strict'
const fastClone = require('rfdc')({ circles: false, proto: true })
const { kSchemaVisited, kSchemaResponse } = require('./symbols')
const kFluentSchema = Symbol.for('fluent-schema-object')
const {
FST_ERR_SCH_MISSING_ID,
FST_ERR_SCH_ALREADY_PRESENT,
FST_ERR_SCH_DUPLICATE,
FST_ERR_SCH_CONTENT_MISSING_SCHEMA
} = require('./errors')
const SCHEMAS_SOURCE = ['params', 'body', 'querystring', 'query', 'headers']
function Schemas (initStore) {
this.store = initStore || {}
}
Schemas.prototype.add = function (inputSchema) {
const schema = fastClone((inputSchema.isFluentSchema || inputSchema.isFluentJSONSchema || inputSchema[kFluentSchema])
? inputSchema.valueOf()
: inputSchema
)
// developers can add schemas without $id, but with $def instead
const id = schema.$id
if (!id) {
throw new FST_ERR_SCH_MISSING_ID()
}
if (this.store[id]) {
throw new FST_ERR_SCH_ALREADY_PRESENT(id)
}
this.store[id] = schema
}
Schemas.prototype.getSchemas = function () {
return Object.assign({}, this.store)
}
Schemas.prototype.getSchema = function (schemaId) {
return this.store[schemaId]
}
/**
* Checks whether a schema is a non-plain object.
*
* @param {*} schema the schema to check
* @returns {boolean} true if schema has a custom prototype
*/
function isCustomSchemaPrototype (schema) {
return typeof schema === 'object' && Object.getPrototypeOf(schema) !== Object.prototype
}
function normalizeSchema (routeSchemas, serverOptions) {
if (routeSchemas[kSchemaVisited]) {
return routeSchemas
}
// ... (148 more lines)
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does schemas.js do?
schemas.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, InstanceFactory subdomain.
What functions are defined in schemas.js?
schemas.js defines 8 function(s): Schemas, add, generateFluentSchema, getSchema, getSchemaSerializer, getSchemas, isCustomSchemaPrototype, normalizeSchema.
Where is schemas.js in the architecture?
schemas.js is located at lib/schemas.js (domain: CoreKernel, subdomain: InstanceFactory, directory: lib).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free