Skip to content

Conversation

@mrnagydavid
Copy link
Collaborator

Before anything: Ajv is one of the most badly documented tool relative to how much documentation is actually produced. It is badly worded, confusing.

In this PR, ChatGPT and I - in close collaboration - implement a parametrizable isoDate schema for Zod and Ajv.

It survives the Zod->Ajv transformation by carrying over the required parameters in the description field of the JSON Schema.


I suggest moving basic Ajv-related logic to js-lib, since with the current setup js-lib imports into nodejs-lib which is not a good direction - even though this is only in tests.

This is because zod and ajv are very closely coupled for us, i.e. we should not implement a zod feature that will be missing in Ajv - so I have to keep these tests closely together.

By moving getAjv() et al to js-lib, this circular dependency would be solved.
We can leave AjvSchema in nodejs-lib, if we want

Copy link
Member

@kirillgroshkov kirillgroshkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss in a call. The magic levels of this PR are nearing the maximum Hogwards-approved levels ⚠️


let error = 'Should be be a YYYY-MM-DD string'
if (after) error = `Should be after ${after}`
if (sameOrAfter) error = `Should be on or after ${sameOrAfter}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3: I prefer else if, which skips evaluating more conditions as soon as it encountered one truthy condition (since they are mutually exclusive)


let schema = z.string().refine(
dateString => {
if (!localDate.isValidString(dateString)) return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that I'm afraid of the performance implications.
In reality we deal with hundreds/thousands of isoDates per "validation run", so, it's very performance-sensitive code, I'd like to scrutinize it.

For example, we could get away with just string comparisons and not relying on LocalDate api.

isValidString can be instead done via regex?

Also, I'd like a fast-pass for case when there are no parameters

@mrnagydavid mrnagydavid force-pushed the DEV-22569-zod-isoDate-params branch from aa6b664 to 58e9f1d Compare September 23, 2025 08:20
@kirillgroshkov kirillgroshkov force-pushed the main branch 2 times, most recently from 1299b0b to 06656e9 Compare December 10, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants