krakenjs / hapi-openapi

Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.
Other
211 stars 75 forks source link

String schema format:date #188

Open danailch456 opened 3 years ago

danailch456 commented 3 years ago

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 commented 3 years ago

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.