Skip to content

Commit

Permalink
Support for hiding Joi properties from being included in Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
leobudima committed Sep 18, 2020
1 parent 82d77ad commit 16a015a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/property-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions usageguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 16a015a

Please sign in to comment.