Skip to content

Commit

Permalink
Merge pull request #368 from apiaryio/361-deprecate-amanda
Browse files Browse the repository at this point in the history
Adds deprecation warning on JSON Schema Draft 3 usage
  • Loading branch information
artem-zakharchenko authored Jan 24, 2020
2 parents 5884b69 + 1c0f9b1 commit 70c7925
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/utils/warn-on-deprecation.js
Original file line number Diff line number Diff line change
@@ -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}`);
}
};
5 changes: 5 additions & 0 deletions lib/validators/json-schema-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 70c7925

Please sign in to comment.