(routeSchemas, serverOptions)
| 56 | } |
| 57 | |
| 58 | function normalizeSchema (routeSchemas, serverOptions) { |
| 59 | if (routeSchemas[kSchemaVisited]) { |
| 60 | return routeSchemas |
| 61 | } |
| 62 | |
| 63 | // alias query to querystring schema |
| 64 | if (routeSchemas.query) { |
| 65 | // check if our schema has both querystring and query |
| 66 | if (routeSchemas.querystring) { |
| 67 | throw new FST_ERR_SCH_DUPLICATE('querystring') |
| 68 | } |
| 69 | routeSchemas.querystring = routeSchemas.query |
| 70 | } |
| 71 | |
| 72 | generateFluentSchema(routeSchemas) |
| 73 | |
| 74 | for (const key of SCHEMAS_SOURCE) { |
| 75 | const schema = routeSchemas[key] |
| 76 | if (schema && !isCustomSchemaPrototype(schema)) { |
| 77 | if (key === 'body' && schema.content) { |
| 78 | const contentProperty = schema.content |
| 79 | const keys = Object.keys(contentProperty) |
| 80 | for (let i = 0; i < keys.length; i++) { |
| 81 | const contentType = keys[i] |
| 82 | const contentSchema = contentProperty[contentType].schema |
| 83 | if (!contentSchema) { |
| 84 | throw new FST_ERR_SCH_CONTENT_MISSING_SCHEMA(contentType) |
| 85 | } |
| 86 | } |
| 87 | continue |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (routeSchemas.response) { |
| 93 | const httpCodes = Object.keys(routeSchemas.response) |
| 94 | for (const code of httpCodes) { |
| 95 | if (isCustomSchemaPrototype(routeSchemas.response[code])) { |
| 96 | continue |
| 97 | } |
| 98 | |
| 99 | const contentProperty = routeSchemas.response[code].content |
| 100 | |
| 101 | if (contentProperty) { |
| 102 | const keys = Object.keys(contentProperty) |
| 103 | for (let i = 0; i < keys.length; i++) { |
| 104 | const mediaName = keys[i] |
| 105 | if (!contentProperty[mediaName].schema) { |
| 106 | throw new FST_ERR_SCH_CONTENT_MISSING_SCHEMA(mediaName) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | routeSchemas[kSchemaVisited] = true |
| 114 | return routeSchemas |
| 115 | } |
no test coverage detected