Open Vamc90 opened 1 year ago
@Vamc90 Because in JSON schema definition, the "date" format must comply to ISO, https://json-schema.org/draft/2020-12/json-schema-core.html#name-format. Hence, it's previously set to only convert to string with format when it's declared as .iso() in joi.date() field.
I am not sure if I should always convert the "date" field to "string" even if it's not explicitly declared iso comply.
While using @joi/date library and trying to initialise a date schema and format in MM/DD/YYYY. Upon converting to Json schema, the value is converted as integer rather than string, where as when date converted as iso[Joi.date().iso()] is converting fine to String as expected.
Snippet: export const DateSchema = Joi.date().format('DD/MM/YYYY').required().example('20/10/2022'); Result
"Date": { "type": "integer", "examples": [ "20/10/2022" ], "description": "Date field" },
Upon going through the joi-to-json source code, we believe it needs a change at this entry https://github.com/kenspirit/joi-to-json/blob/master/lib/parsers/json.js#L509