diff --git a/lib/properties.js b/lib/properties.js index 7c267ff3..93521edd 100644 --- a/lib/properties.js +++ b/lib/properties.js @@ -73,6 +73,9 @@ internals.properties.prototype.parseProperty = function(name, joiObj, parent, pa return undefined; } + if (Utilities.getJoiMetaProperty(joiObj, 'swaggerHidden') === true) { + return undefined; + } // default the use of definitions to true if (useDefinitions === undefined || useDefinitions === null) { useDefinitions = true; diff --git a/test/unit/property-test.js b/test/unit/property-test.js index 5fe2f0c8..250d472b 100644 --- a/test/unit/property-test.js +++ b/test/unit/property-test.js @@ -179,6 +179,18 @@ lab.experiment('property - ', () => { expect(nonNegativeWithoutDropdown).to.not.include({ enum: [0] }); }); + lab.test('parse hidden', () => { + expect( + propertiesAlt.parseProperty('x', Joi.string().meta({ swaggerHidden: true }), null, 'body', true, false) + ).to.equal(undefined); + expect( + propertiesAlt.parseProperty('x', Joi.string().meta({ swaggerHidden: false }), null, 'body', true, false) + ).to.equal({ + type: 'string', + 'x-meta': { swaggerHidden: false } + }); + }); + lab.test('parse type string', () => { clearDown(); expect(propertiesNoAlt.parseProperty('x', Joi.string(), null, 'body', true, false)).to.equal({ diff --git a/usageguide.md b/usageguide.md index 8c7f29e9..94c21395 100644 --- a/usageguide.md +++ b/usageguide.md @@ -14,6 +14,7 @@ - [Status Codes](#status-codes) - [Caching](#caching) - [File upload](#file-upload) +- [Prevent JOI properties from being included in the Swagger schema](#prevent-joi-properties-from-being-included-in-the-swagger-schema) - [Headers and .unknown()](#headers-and-unknown) - [Additional Hapi data using x-\*](#additional-hapi-data-using-x-) - [JSON without UI](#json-without-ui) @@ -468,6 +469,12 @@ the three important elements are: } ``` +## Prevent JOI properties from being included in the Swagger schema + +You can prevent specific JOI properties from being included in the generated Swagger schema by using: + +`.meta({ swaggerHidden: true })` + ## Default values and examples You can add both default values and examples to your JOI objects which are displayed within the Swagger interface.