Cody2333 / koa-swagger-decorator

using decorator to automatically generate swagger doc for koa-router
348 stars 81 forks source link

date format should check 'yyyy-MM-dd' as stated in OpenAPI definition #157

Open paoesco opened 2 years ago

paoesco commented 2 years ago

Hello,

It seems date and date-time formats are both treated as date-time in the validation, but date should accept date only values like 2022-01-01.

According to OpenAPI documentation:

An optional format modifier serves as a hint at the contents and format of the string. OpenAPI defines the following built-in string formats:
date – full-date notation as defined by [RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6), for example, 2017-07-21
date-time – the date-time notation as defined by [RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6), for example, 2017-07-21T17:32:28Z

Culprit is in check.ts

  if ((expect.format === 'date' || expect.format === 'date-time') && !validator.isRFC3339(val)) return { is: false };

Thanks