MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / schemaValidation

Function schemaValidation

client/i18n/schema-validation.ts:197–226  ·  view source on GitHub ↗
(
  language: string,
  fileName: string,
  fileJson: Record<string, unknown>,
  schemaKeys: string[]
)

Source from the content-addressed store, hash-verified

195 * @param {String[]} schemaKeys Array of matching schema's keys
196 */
197const schemaValidation = (
198 language: string,
199 fileName: string,
200 fileJson: Record<string, unknown>,
201 schemaKeys: string[]
202) => {
203 const fileKeys = Object.keys(flattenAnObject(fileJson));
204 findMissingKeys(fileKeys, schemaKeys, `${language}/${fileName}.json`);
205 findExtraneousKeys(fileKeys, schemaKeys, `${language}/${fileName}.json`);
206 const emptyKeys = noEmptyObjectValues(fileJson);
207 if (emptyKeys.length) {
208 console.warn(
209 `${language}/${fileName}.json has these empty keys: ${emptyKeys.join(
210 ', '
211 )}`
212 );
213 }
214 // Special line to assert that objects in motivational quote are correct
215 if (
216 fileName === 'motivation' &&
217 !(fileJson.motivationalQuotes as MotivationalQuotes).every(
218 object =>
219 Object.prototype.hasOwnProperty.call(object, 'quote') &&
220 Object.prototype.hasOwnProperty.call(object, 'author')
221 )
222 ) {
223 console.warn(`${language}/${fileName}.json has malformed quote objects.`);
224 }
225 console.info(`${language} ${fileName}.json validation complete`);
226};
227
228const readJsonFile = async (language: string, fileName: string) => {
229 const filePath = path.join(

Callers 5

introSchemaValidationFunction · 0.85
metaTagsSchemaValidationFunction · 0.85
linksSchemaValidationFunction · 0.85

Calls 4

flattenAnObjectFunction · 0.85
findMissingKeysFunction · 0.85
findExtraneousKeysFunction · 0.85
noEmptyObjectValuesFunction · 0.85

Tested by

no test coverage detected