Skip to content

Commit

Permalink
Move array-check for the 'examples' property to the TypeMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
bravo-kernel committed Aug 24, 2019
1 parent e91565c commit eb3edf0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
8 changes: 7 additions & 1 deletion lib/schema-manager.js
Expand Up @@ -439,12 +439,18 @@ class SchemaManager {
* @returns {string}
*/
_getAttributeExamples(attributeName, attributeProperties) {
// skip if user has not defined examples
if (!this.constructor._hasCustomAttributeProperty(attributeProperties, 'examples')) {
return null; // user has not defined examples
return null;
}

const { examples } = attributeProperties.jsonSchema;

// see https://json-schema.org/understanding-json-schema/reference/generic.html
if (!Array.isArray(examples)) {
throw new TypeError("The 'examples' property MUST be an array");
}

return _strategy.get(this).getPropertyExamples(examples);
}
}
Expand Down
4 changes: 0 additions & 4 deletions lib/strategies/openapi-v3.js
Expand Up @@ -72,10 +72,6 @@ class OpenApi3Strategy extends StrategyInterface {
* @returns {object}
*/
getPropertyExamples(examples) {
if (!Array.isArray(examples)) {
throw new TypeError("OpenAPI 3.0 requires type 'array' for the 'example' property");
}

return {
example: examples,
};
Expand Down
9 changes: 0 additions & 9 deletions lib/strategy-interface.js
Expand Up @@ -7,15 +7,6 @@
* @license Licensed under the MIT License
*/
class StrategyInterface {
/**
* Must return the full URI to the strategy-specific online json (validation) schema.
*
* @returns {string}
*/
getOnlineSchemaUri() {
this.constructor._throwMissingImplementationError(this.constructor.name, 'getOnlineSchemaUri');
}

/**
* Must return the property used as "schema".
*
Expand Down
2 changes: 1 addition & 1 deletion test/strategy-interface.test.js
Expand Up @@ -12,7 +12,7 @@ describe('StrategyInterface', function() {
const methodCount = Object.getOwnPropertyNames(StrategyInterface.prototype).length - 1; // excluding the constructor

it(`8 interface methods`, function() {
expect(methodCount).toEqual(9);
expect(methodCount).toEqual(8);
});
});

Expand Down

0 comments on commit eb3edf0

Please sign in to comment.