Skip to content

fix: extend type from fastify/ajv-compiler for ajv field in fastify options#6223

Closed
gianmarco27 wants to merge 13 commits intofastify:mainfrom
gianmarco27:fix/ajv-options-typings
Closed

fix: extend type from fastify/ajv-compiler for ajv field in fastify options#6223
gianmarco27 wants to merge 13 commits intofastify:mainfrom
gianmarco27:fix/ajv-options-typings

Conversation

@gianmarco27
Copy link
Contributor

@gianmarco27 gianmarco27 commented Jun 17, 2025

As I was trying to add a custom validation pattern to Ajv through the ajv.onCreate property, as suggested in the fastify/ajv-compiler documentation, I incurred in a TS error for the FastifyServerOptions that although proxies the entire ajv property to the fastify/ajv-compiler builder method, does not expose correctly all of its properties into the typings.

This small change in the typings correctly exposes the available options, and should be future proof as the type is directly derived from the fastify/ajv-compiler types.

Checklist

@github-actions github-actions bot added typescript TypeScript related documentation Improvements or additions to documentation labels Jun 17, 2025
@gianmarco27 gianmarco27 reopened this Jun 17, 2025
@gianmarco27 gianmarco27 force-pushed the fix/ajv-options-typings branch 3 times, most recently from 19707c0 to 36a5cfd Compare June 17, 2025 21:35
@gianmarco27 gianmarco27 force-pushed the fix/ajv-options-typings branch from 36a5cfd to f6ba466 Compare June 17, 2025 21:45
@jean-michelet
Copy link
Member

Thanks for the PR!

Unfortunately, I don't know this part of the framework well enough to give quality feedback, so I will let an other contributor review your work.

But I think you should write a test to prove that onCreate integrates correctly with Fastify (I don't see any test on that regard in the core), and you should probably write typing tests too.

Typing tests are here:
https://github.com/fastify/fastify/tree/main/test/types

I am not sure where to write the integration test for onCreate, maybe here:
https://github.com/fastify/fastify/blob/main/test/schema-special-usage.test.js

@gianmarco27
Copy link
Contributor Author

Thank you for the quick feedback! I'll be on it ASAP

@jean-michelet jean-michelet requested a review from a team September 21, 2025 09:42
@Eomm Eomm requested a review from a team October 6, 2025 09:14
@Eomm Eomm added the bugfix Issue or PR that should land as semver patch label Oct 6, 2025
@gianmarco27 gianmarco27 requested a review from Eomm October 19, 2025 11:30
Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

Fixed fastify/ajv-compiler#157

Closing

@Eomm Eomm closed this Nov 9, 2025
@gianmarco27
Copy link
Contributor Author

gianmarco27 commented Nov 11, 2025

Hey @Eomm, i thin this is still missing in fastify, as the type, although fixed in ajv-compiler, is not being imported and proxied correctly from fastify types. (Bonus: some docs)

Specifically referring to these changes:
https://github.com/fastify/fastify/pull/6223/files#diff-a22e7d603319a7f6d79163f6687b3d980db8627df7fcdcae09a087df9ea06a98L156-R156

@Eomm
Copy link
Member

Eomm commented Nov 11, 2025

The oncreate and plugins options have been handled in 157 - if you think there is something still missing, please open a new PR or an issue with the snippet to reproduce the issue.

I see the value in your link to generalize this part

fastify/fastify.d.ts

Lines 156 to 159 in 27e3fe3

ajv?: {
customOptions?: AjvOptions,
plugins?: (Function | [Function, unknown])[]
},

@gianmarco27 gianmarco27 mentioned this pull request Jan 2, 2026
4 tasks
@gianmarco27 gianmarco27 deleted the fix/ajv-options-typings branch January 2, 2026 20:50
@gianmarco27 gianmarco27 restored the fix/ajv-options-typings branch January 2, 2026 20:50
@gianmarco27 gianmarco27 deleted the fix/ajv-options-typings branch January 2, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Issue or PR that should land as semver patch documentation Improvements or additions to documentation typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants