express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

formats as an array is deprecated. Use object instead

Open rafaelmaeuer opened this issue 2 years ago • 1 comments

Describe the bug When using the formats property as described in the docs: https://github.com/cdimascio/express-openapi-validator/wiki/Documentation#%EF%B8%8F-formats-optional I get following warning:

formats as an array is deprecated. Use object instead https://ajv.js.org/options.html#formats

To Reproduce Setup express-server and use OpenApiValidator middleware with following config:

formats: [
  {
    name: 'iso8601-timestamp',
    type: 'string',
  validate: (value) => moment(value, moment.ISO_8601).isValid(),
  },
],

Actual behavior Warning is shown on server-start.

Expected behavior No warning should be shown on server-start.

Examples and context Please consider upgrading to current Ajv schema: https://ajv.js.org/options.html#formats

rafaelmaeuer avatar Mar 07 '23 14:03 rafaelmaeuer

This is easy to fix by using object instead of an array like:

formats: {
    "iso8601-timestamp": {
      type: 'string',
      validate: (value) => moment(value, moment.ISO_8601).isValid(),
  }
},

Right?

hkroger avatar May 17 '23 15:05 hkroger