diff --git a/lib/utils/warn-on-deprecation.js b/lib/utils/warn-on-deprecation.js new file mode 100644 index 00000000..caca86fb --- /dev/null +++ b/lib/utils/warn-on-deprecation.js @@ -0,0 +1,16 @@ +/* eslint-disable no-console */ + +/** + * Outputs a deprecation message. + * Supports silencing the messages based on the environmental variable. + * @param {string} message + */ +module.exports = function warnOnDeprecation(message) { + const shouldOutputMessage = + typeof process === 'undefined' || + !process.env.SUPPRESS_DEPRECATION_WARNINGS; + + if (shouldOutputMessage) { + console.warn(`DEPRECATED: ${message}`); + } +}; diff --git a/lib/validators/json-schema-legacy.js b/lib/validators/json-schema-legacy.js index d54dc9ca..bef19fc5 100644 --- a/lib/validators/json-schema-legacy.js +++ b/lib/validators/json-schema-legacy.js @@ -5,6 +5,7 @@ const jsonPointer = require('json-pointer'); const { JsonSchemaValidator, META_SCHEMA } = require('./json-schema-next'); const { ValidationErrors } = require('./validation-errors'); const toGavelResult = require('../utils/to-gavel-result'); +const warnOnDeprecation = require('../utils/warn-on-deprecation'); /** * Returns a proper article for a given string. @@ -76,6 +77,10 @@ class JsonSchemaLegacy extends JsonSchemaValidator { switch (this.jsonSchemaVersion) { case 'draftV3': + warnOnDeprecation( + 'JSON Schema Draft V3 is deprecated. Please use a newer version of JSON Schema (Draft V4-7).' + ); + return this.validateUsingAmanda(parsedData); case 'draftV4': return this.validateUsingTV4(parsedData);