Repository: glennjones/hapi-swagger (js)

Issue:
invalid swagger generated for Joi.date().min(Joi.ref('reference'))
#### Context

* *hapi-swagger version*: 7.7.0

#### What are you trying to achieve or the steps to reproduce ?
I would like to use Joi to validate that an end date is greater than a start date.
The validation works fine, but the swagger that hapi-swagger generates is invalid.

```js
start: Joi.date(),
end: Joi.date().min(Joi.ref('start')),
```

#### What result did you get?
Validation works fine, but hapi-swagger generates : 
```js
"start":{"type":"string","format":"date"}
"end":{"type":"string","format":"date","minLength":"ref:start"}
```
But this is invalid.  Using http://editor.swagger.io/, I get this error message.
```js
"code":"INVALID_TYPE","params":["integer","string"],"message":"Expected type integer but found type string"
```

#### What did you expect ?
I expected to have a valid swagger

Pull request description:
Ignore date.min() and date.max() to avoid creating invalid swagger
Currently using date().min() and date().max() will result in an invalid swagger.json,
for example:

`date().min('1-1-1974')` will result in

```json
{
  "format": "date",
  "maxLength": "now",
   "type": "string"
}
```

Which is both invalid since maxLength must be an integer and obviously not what is meant by the Joi schema.

Couldn't find a reference that OpenAPI indeed doesn't support date range rules, but found no refrence that it does support it either.

Fixes #417

Patch:
diff --git a/lib/properties.js b/lib/properties.js
index ee3db30..3c3b7ba 100644
--- a/lib/properties.js
+++ b/lib/properties.js
@@ -265,8 +265,10 @@ internals.properties.prototype.parseString = function (property, joiObj) {
 
     const describe = joiObj.describe();
 
-    property.minLength = internals.getArgByName(describe.rules, 'min');
-    property.maxLength = internals.getArgByName(describe.rules, 'max');
+    if (describe.type !== 'date') {
+        property.minLength = internals.getArgByName(describe.rules, 'min');
+        property.maxLength = internals.getArgByName(describe.rules, 'max');
+    }
 
     // add regex
     joiObj._tests.forEach((test) => {
diff --git a/usageguide.md b/usageguide.md
index 7b8e2c6..74f409d 100644
--- a/usageguide.md
+++ b/usageguide.md
@@ -493,6 +493,7 @@ Not all the flexibility of HAPI and JOI can to ported over to the Swagger schema
 * __`.allow( null )`__  The current Swagger spec does not support `null`. This __maybe__ added to the next version of OpenAPI spec.
 * __`payload: function (value, options, next) {next(null, value);}`__  The use of custom functions to validate pramaters is not support beyond replacing them with an emtpy model call "Hidden Model".
 * __`Joi.date().format('yy-mm-dd')` __ The use of a `moment` pattern to format a date cannot be reproduced in Swagger
+* __`Joi.date().min()` and `Joi.date().max()`__ Minimum or maximum dates cannot be expressed in Swagger.
 
 
 # Known issues with `jsonEditor`


Test patch:
diff --git a/test/unit/property-test.js b/test/unit/property-test.js
index 1ab1132..d245543 100644
--- a/test/unit/property-test.js
+++ b/test/unit/property-test.js
@@ -203,6 +203,16 @@ lab.experiment('property - ', () => {
         clearDown();
         expect(propertiesNoAlt.parseProperty('x', Joi.date(), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
 
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().min('1-1-1974'), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().min('now'), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().min(Joi.ref('y')), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().max('1-1-1974'), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().max('now'), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().max(Joi.ref('y')), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+
+        expect(propertiesNoAlt.parseProperty('x', Joi.date().min('1-1-1974').max('now'), null, 'body', true, false)).to.equal({ 'type': 'string', 'format': 'date' });
+
         /*  not yet 'x',
         date.min(date)
         date.max(date)