ajv icon indicating copy to clipboard operation
ajv copied to clipboard

JTD schemas do not support coerceTypes option

Open riker09 opened this issue 4 years ago • 3 comments
trafficstars

I'm using TypeScript v4.3.4 and I am unable to use the coerceTypes option when constructing the Ajv instance.

import Ajv from 'ajv/dist/jtd';

const ajv = new Ajv({ coerceTypes: true });

This is a screenshot of the error I get in VSCodium v1.57.1:

Bildschirmfoto von 2021-06-28 09-13-51

riker09 avatar Jun 28 '21 07:06 riker09

JTD schemas do not support type coercion.

epoberezkin avatar Aug 01 '21 10:08 epoberezkin

Why?

egorkel-altexsoft avatar Apr 06 '22 10:04 egorkel-altexsoft

@epoberezkin, Do you have any plans to support the coerceTypes option or is this not possible in case of JTD?

curvedriver avatar May 09 '22 08:05 curvedriver

Ran into the same issue today. Really happy with JTD type generation, but working against an inconsistent API makes coercion kind of a hassle.

I wrote a small helper to wrap Ajv validator and do simple coercion. It's not extensively tested, but I'll update it if I run into bugs until this is an official feature: https://gist.github.com/fabianeichinger/f9bad3ee17d637ac3778448d0fb0f528

fabianeichinger avatar Nov 18 '22 17:11 fabianeichinger