Skip to content

Commit

Permalink
Cleanup and refactoring for improved readability and more logical order
Browse files Browse the repository at this point in the history
  • Loading branch information
bravo-kernel committed Aug 15, 2019
1 parent 17df0ad commit 35661af
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 71 deletions.
4 changes: 2 additions & 2 deletions lib/schema-manager.js
Expand Up @@ -14,14 +14,14 @@ const StrategyInterface = require('./strategy-interface');
const _options = new WeakMap();

/**
* Passed schema strategy.
* Strategy instance passed to the `generate()` method.
*
* @private
*/
const _strategy = new WeakMap();

/**
* Passed Sequelize model.
* Sequelize model instance passed to the `generate()` method.
*
* @private
*/
Expand Down
36 changes: 8 additions & 28 deletions lib/strategies/json-schema-v6.js
@@ -1,6 +1,5 @@
/* eslint-disable class-methods-use-this */

const _ = require('lodash');
const StrategyInterface = require('../strategy-interface');

/**
Expand All @@ -10,33 +9,14 @@ const StrategyInterface = require('../strategy-interface');
*/
class JsonSchema6Strategy extends StrategyInterface {
/**
* Class constructor.
*
* @param {object} config
*/
constructor(config) {
super();

// strategy specific configuration options.FYI we are disabling prettier
// for the instantiation because it conflicts with the esline rule.
// prettier-ignore
const _defaultConfig = { // eslint-disable-line no-underscore-dangle
woot: null,
};

// merge and verify settings
this._config = _.merge({}, _defaultConfig, config); // eslint-disable-line no-underscore-dangle
}

/**
* Returns the keyword used for the "identifier" property.
* Returns the full URI to the online JSON Schema v6 schema (validation) file.
*
* @example $id
* @example https://json-schema.org/draft-06/schema#
*
* @returns {string}
*/
getIdentifierKeyword() {
return '$id';
getSchemaUri() {
return 'https://json-schema.org/draft-06/schema#';
}

/**
Expand All @@ -51,14 +31,14 @@ class JsonSchema6Strategy extends StrategyInterface {
}

/**
* Returns the full URI to the online JSON Schema v6 schema (validation) file.
* Returns the keyword used for the "identifier" property.
*
* @example https://json-schema.org/draft-06/schema#
* @example $id
*
* @returns {string}
*/
getSchemaUri() {
return 'https://json-schema.org/draft-06/schema#';
getIdentifierKeyword() {
return '$id';
}
}

Expand Down
38 changes: 9 additions & 29 deletions lib/strategies/openapi-v3.js
@@ -1,6 +1,5 @@
/* eslint-disable class-methods-use-this */

const _ = require('lodash');
const StrategyInterface = require('../strategy-interface');

/**
Expand All @@ -10,27 +9,20 @@ const StrategyInterface = require('../strategy-interface');
*/
class OpenApi3Strategy extends StrategyInterface {
/**
* Class constructor.
* Returns the full URI to the online OpenAPI v3 schema (validation) file.
*
* @param {object} config Strategy configuration options
*/
constructor(config) {
super();

// strategy specific configuration options.FYI we are disabling prettier
// for the instantiation because it conflicts with the esline rule.
// prettier-ignore
const _defaultConfig = { // eslint-disable-line no-underscore-dangle
woot: null,
};
* @example https://github.com/OAI/OpenAPI-Specification/raw/master/schemas/v2.0/schema.json
// merge and verify settings
this._config = _.merge({}, _defaultConfig, config); // eslint-disable-line no-underscore-dangle
* @returns {string}
*/
// prettier-ignore
getSchemaUri() { // eslint-disable-line no-unused-vars
return 'https://json-schema.org/draft-06/schema#';
}

/**
* OpenAPI v3 does not support/allow support the "identifier" property so we
* omit the property from appearing in the schema by returning `null`
* omit the property from appearing in the schema by returning `null`.
*
* @example null
*
Expand All @@ -42,7 +34,7 @@ class OpenApi3Strategy extends StrategyInterface {

/**
* OpenAPI v3 does not support/allow support the "schema" property so we
* omit the property from appearing in the schema by returning `null`
* omit the property from appearing in the schema by returning `null`.
*
* @example null
*
Expand All @@ -51,18 +43,6 @@ class OpenApi3Strategy extends StrategyInterface {
getSchemaKeyword() {
return null;
}

/**
* Returns the full URI to the online OpenAPI v3 schema (validation) file.
*
* @example https://github.com/OAI/OpenAPI-Specification/raw/master/schemas/v2.0/schema.json
* @returns {string}
*/
// prettier-ignore
getSchemaUri() { // eslint-disable-line no-unused-vars
return 'https://json-schema.org/draft-06/schema#';
}
}

module.exports = OpenApi3Strategy;
24 changes: 12 additions & 12 deletions lib/strategy-interface.js
Expand Up @@ -10,16 +10,12 @@ const _throwMissingImplementationError = Symbol('Private method');
*/
class StrategyInterface {
/**
* Must return the keyword used for the "identifier" schema property or `null`
* to omit the property from appearing in the schema.
* Must return the full URI to the strategy specific online json (validation) schema.
*
* @see {@link https://json-schema.org/understanding-json-schema/structuring.html#the-id-property}
* @param {string} path Path
* @returns {string|null}
* @returns {string}
*/
// prettier-ignore
getIdentifierKeyword() {
this[_throwMissingImplementationError](this.constructor.name, 'getIdentifierKeyword');
getSchemaUri() {
this[_throwMissingImplementationError](this.constructor.name, 'getSchemaUri');
}

/**
Expand All @@ -36,12 +32,16 @@ class StrategyInterface {
}

/**
* Must return the full URI to the strategy specific online json (validation) schema.
* Must return the keyword used for the "identifier" schema property or `null`
* to omit the property from appearing in the schema.
*
* @returns {string}
* @see {@link https://json-schema.org/understanding-json-schema/structuring.html#the-id-property}
* @param {string} path Path
* @returns {string|null}
*/
getSchemaUri() {
this[_throwMissingImplementationError](this.constructor.name, 'getSchemaUri');
// prettier-ignore
getIdentifierKeyword() {
this[_throwMissingImplementationError](this.constructor.name, 'getIdentifierKeyword');
}

/**
Expand Down

0 comments on commit 35661af

Please sign in to comment.