MCPcopy
hub / github.com/fastify/fastify / compileSchemasForSerialization

Function compileSchemasForSerialization

lib/validation.js:18–55  ·  view source on GitHub ↗
(context, compile)

Source from the content-addressed store, hash-verified

16const { FSTWRN001 } = require('./warnings')
17
18function compileSchemasForSerialization (context, compile) {
19 if (!context.schema || !context.schema.response) {
20 return
21 }
22 const { method, url } = context.config || {}
23 context[responseSchema] = Object.keys(context.schema.response)
24 .reduce(function (acc, statusCode) {
25 const schema = context.schema.response[statusCode]
26 statusCode = statusCode.toLowerCase()
27 if (!scChecker.test(statusCode)) {
28 throw new FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX()
29 }
30
31 if (schema.content) {
32 const contentTypesSchemas = {}
33 for (const mediaName of Object.keys(schema.content)) {
34 const contentSchema = schema.content[mediaName].schema
35 contentTypesSchemas[mediaName] = compile({
36 schema: contentSchema,
37 url,
38 method,
39 httpStatus: statusCode,
40 contentType: mediaName
41 })
42 }
43 acc[statusCode] = contentTypesSchemas
44 } else {
45 acc[statusCode] = compile({
46 schema,
47 url,
48 method,
49 httpStatus: statusCode
50 })
51 }
52
53 return acc
54 }, {})
55}
56
57function compileSchemasForValidation (context, compile, isCustom) {
58 const { schema } = context

Callers 1

addNewRouteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected