Hacker News new | ask | show | jobs
Validating Next.js API routes with object schemas (next-rest-framework.vercel.app)
2 points by blomqma 1265 days ago
2 comments

Something that would get me to adopt this library would be the ability to auto-generate OpenAPI specs. Currently I use typoa [1] and manually wire it up in a catch-all API route.

[1] https://github.com/Eywek/typoa

Yes, having a decorator-free approach was one of the main reasons why I started working on this - I've currently implemented the OpenAPI instrumentation in a way that all of your endpoints are called with specific headers that make those endpoints return their own API spec, generated from the parameters that they are defined with. While this might sound a bit IO-heavy with a potentially high amount of network requests, it is done only when calling the Swagger UI endpoint and it can be improved with some caching, I think.
I created an example on how one can easily add both compile-time and runtime validation with object schemas for their Next.js API routes using Next REST Framework, which is a framework for creating type-safe, self-documenting REST APIs for Next.js authored by yours truly.