Closed robogeek closed 8 months ago
To properly validate formats like date-time
, you should extend ajv with ajv-formats.
import addFormats from 'ajv-formats';
const api = new OpenAPIBackend({
definition,
customizeAjv: (ajv) => {
addFormats(ajv, { mode: 'fast', formats: ['date-time'] });
return ajv;
},
});
See: https://openapistack.co/docs/openapi-backend/request-validation/#extended-formats
As I said in the other issue - what you're suggesting is not what I am wanting. It shouldn't throw an error because a valid/legitimate format has been declared.
I see. The warnings are generated by Ajv, and are indeed useful for openapi-backend users as an indicator of needing to add validators. Perhaps see if ajv has an option to turn these warnings off?
If I enable some AJV code, does it force me into using AJV validation? I don't understand the impact, and am using Joi for validation instead.
If you have no need for validation, you can just pass validate: false
in the constructor so Ajv never gets initialised, effectively disabling these warnings.
The specification I'm working with uses ISO 8601 date-time strings, of course. The declaration for the corresponding schema object is:
When executing the test suite, a zillion error messages like this are printed:
The messages go away when commenting the
format: date-time
specification.