segmentio / typewriter

Type safety + intellisense for your Segment analytics
https://segment.com/docs/protocols/typewriter/
MIT License
227 stars 53 forks source link

In development Mode ajv.validate causes Error: unknown format "date-time" #307

Open ishields opened 1 year ago

ishields commented 1 year ago

I am seeing an issue in the generated segment.ts in which I receive an error

Error: unknown format "date-time" ignored in schema at path "#/properties/...."

My fix right now is to do

import addFormats from 'ajv-formats'

Then change the generated method to

function validateAgainstSchema(message: Record<string, any>, schema: object) {
    const ajv = new Ajv({ allErrors: true, verbose: true })
    //@ts-ignore
    addFormats(ajv)
    if (!ajv.validate(schema, message) && ajv.errors) {
        onViolation(message, ajv.errors)
    }
}

This is obviously not ideal because this is a generated file that shouldn't be edited.

Is there a recommended solution to this?

I'm using these package versions:

    "ajv": "^8.12.0",
    "ajv-formats": "2.1.1",
    "typewriter": "9.0.0",