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

Add option to use AJV Standalone #297

Open
rehanvdm opened this issue Jan 22, 2022 · 3 comments
Open

Add option to use AJV Standalone #297

rehanvdm opened this issue Jan 22, 2022 · 3 comments
Labels

Comments

@rehanvdm
Copy link

I saw this issue #114 and the resulting PR, which lazy loads schemas, which is great for environments like AWS Lambda.

There is now a new method in AJV 8 to generate the schemas to JS functions at compile time so that they can be used at runtime, no more compiling schemas at runtime which saves a lot of time. You can read more about the process here: https://ajv.js.org/standalone.html and I also wrote a blog about it here: https://www.rehanvdm.com/blog/typescript-type-safety-with-ajv-standalone. . Fastify also added the option recently, might be worth seeing their implementation.

One of the main reasons I chose this package is because it uses AJV for validation instead of the other validation libraries that can be slow.

@anttiviljami
Copy link
Member

Amazing! Thanks for bringing this to my attention @rehanvdm 💪

@rehanvdm
Copy link
Author

rehanvdm commented Feb 2, 2022

So I have a 3000 lines Open API spec that takes about 7 seconds to load on a AWS Lambda @1024mb when quick is set to false 😲. With quick true it takes about 80ms, and then the input (path, query, body) validation about 100ms and the response about 10ms. That only happens the first time so the quick option is doing its job. I still feel that it can be improved by using the standalone mode.

Do you have any plans to maybe tackle this within the next few weeks/months/roadmap? Do you think it would be possible to somehow use the customizeAjv function when creating the OpenAPIBackend object to load the schemas in there then?

@anttiviljami
Copy link
Member

@rehanvdm tbh no clue when I'd get to this. PRs would be highly appreciated <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants