hapi-openapi icon indicating copy to clipboard operation
hapi-openapi copied to clipboard

String schema format:date

Open danailch456 opened this issue 4 years ago • 1 comments

I have the following query parameter in the spec:

name: fromDate
in: query
description: A beginning date of the time range in yyyy-mm-dd format
required: false
schema:
  type: string
  format: date

When I setup the route with hapi-openapi and send a request with query ?fromDate=2014-10-14, the validation passes successfully, but the route handler recieves ?fromDate=Tue+Oct+14+2014+03%3A00%3A00+GMT%2B0300+%28Eastern+European+Summer+Time%29. According to the openapi specification the 'date' format' should represent a date in yyyy-mm-dd. Modifying the query params during validation seems odd and unnecessary. I hope this gets fixed soon.

danailch456 avatar Mar 04 '21 15:03 danailch456

I think the bug comes from generating the joi schema for validating date. After converting the string to date, .raw should be called to preserve the input yyyy-mm-dd format. More info here.

danailch456 avatar Mar 15 '21 16:03 danailch456