validation.js — fastify Source File
Architecture documentation for validation.js, a javascript file in the fastify codebase.
Entity Profile
Relationship Graph
Source Code
'use strict'
const {
kSchemaHeaders: headersSchema,
kSchemaParams: paramsSchema,
kSchemaQuerystring: querystringSchema,
kSchemaBody: bodySchema,
kSchemaResponse: responseSchema
} = require('./symbols')
const scChecker = /^[1-5](?:\d{2}|xx)$|^default$/
const {
FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX
} = require('./errors')
const { FSTWRN001 } = require('./warnings')
function compileSchemasForSerialization (context, compile) {
if (!context.schema || !context.schema.response) {
return
}
const { method, url } = context.config || {}
context[responseSchema] = Object.keys(context.schema.response)
.reduce(function (acc, statusCode) {
const schema = context.schema.response[statusCode]
statusCode = statusCode.toLowerCase()
if (!scChecker.test(statusCode)) {
throw new FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX()
}
if (schema.content) {
const contentTypesSchemas = {}
for (const mediaName of Object.keys(schema.content)) {
const contentSchema = schema.content[mediaName].schema
contentTypesSchemas[mediaName] = compile({
schema: contentSchema,
url,
method,
httpStatus: statusCode,
contentType: mediaName
})
}
acc[statusCode] = contentTypesSchemas
} else {
acc[statusCode] = compile({
schema,
url,
method,
httpStatus: statusCode
})
}
return acc
}, {})
}
function compileSchemasForValidation (context, compile, isCustom) {
const { schema } = context
if (!schema) {
return
// ... (221 more lines)
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does validation.js do?
validation.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 validation.js?
validation.js defines 10 function(s): compileSchemasForSerialization, compileSchemasForValidation, getEssenceMediaType, validate, validateAsyncBody, validateAsyncHeaders, validateAsyncParams, validateAsyncQuery, validateParam, wrapValidationError.
Where is validation.js in the architecture?
validation.js is located at lib/validation.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