Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "must match format 'time'" after upgrading to fastify v5 #267

Open
2 tasks done
AlexisMunozC opened this issue Feb 11, 2025 · 7 comments
Open
2 tasks done

Error "must match format 'time'" after upgrading to fastify v5 #267

AlexisMunozC opened this issue Feb 11, 2025 · 7 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@AlexisMunozC
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.x.x

Plugin version

No response

Node.js version

22.9.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04

Description

I have an endpoint in my Fastify API where in the body I request a field with the type "string" and format "time", in Fastify v4.x.x I passed the format "HH:MM:SS" and it is accepted but after upgrading to v5 running the same test and without modifying anything else I got the error:
{ statusCode: 400, error: 'Bad Request', message: 'body/check_in_time must match format "time"' }

I already checked and when I have the ajv dependency in the last version in Fastify v4 works but in Fastify v5, it doesn't, so it's no problem of ajv.

I have created a simple repository with the example, you just need to change the fastify version and make a request like in the test.http file.

Link to code that reproduces the bug

https://github.com/AlexisMunozC/fastify_error

Expected Behavior

I would expect the format "time" has not changed, or at least describe it to know which is the new format expected.

@metcoder95
Copy link
Member

I can reproduce the problem, tho I'm not able to find yet what is exactly the change.
The Ajv instance is managed by @fastify/ajv-compiler and automatically adds ajv-formats if not explicitly passed through fastifyoptions.ajv.plugins.

Will try to spend more time to see what might be missing

@alexcroox
Copy link

alexcroox commented Feb 28, 2025

Fastify v5 updated AJV compiler which also updated AJV formats which enforces the use of timezone in time and date-time.

This should be mentioned in the migration guide as it broke a lot for us too.

There is a workaround to add backwards comptability using iso-time and iso-date-time but it's been stuck in pre-release since 2021: https://github.com/ajv-validator/ajv-formats/releases

Maybe @mcollina or @epoberezkin can provide some guidance on how to navigate this?

@mcollina
Copy link
Member

@alexcroox that seems incorrect. We use version of ajv-format 3.0.1, which should include all the fixed in the prerelease version you linked.

@jasoniangreen maybe can you help here?

I don't think we were really aware of any breaking changes in those area. Would you like to send a PR to improve the migration guide?

@alexcroox
Copy link

alexcroox commented Feb 28, 2025

@mcollina sorry I missed out a key piece of info, the startup error comes from fluent-json-schema which doesn't have the iso-date-time in the allowed formats:

https://github.com/fastify/fluent-json-schema/blob/main/types/FluentJSONSchema.d.ts#L38-L53

Image

@Eomm
Copy link
Member

Eomm commented Feb 28, 2025

I think the culprit has been already found:

There is a workaround to add backwards comptability using iso-time and iso-date-time but it's been stuck in pre-release since 2021: https://github.com/ajv-validator/ajv-formats/releases

While the GH Release is in draft, the npm versions tell us another story the v3.0.1 is a thing:

We should definetly mention this change in the migration guide

@mcollina
Copy link
Member

@mcollina sorry I missed out a key piece of info, the startup error comes from fluent-json-schema which doesn't have the iso-date-time in the allowed formats:

https://github.com/fastify/fluent-json-schema/blob/main/types/FluentJSONSchema.d.ts#L38-L53

Image

would you like to send a PR to add it?

@climba03003 climba03003 transferred this issue from fastify/fastify Mar 4, 2025
@climba03003
Copy link
Member

Related to #254

@Eomm Eomm added bug Something isn't working good first issue Good for newcomers labels Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants