All notable changes to this project will be documented in this file. We follow the Semantic Versioning 2.0.0 format.
- Silence generate errors for finding NRF config from docs routes.
- Add support for CJS imports in generate.
- Add proper error handling for generating OpenAPI paths from routes & API routes.
- Fix inferred request body type for RPC API routes.
- Add dynamically included JSON schemas for request body, query and path parameter validation errors when validation schemas for them exist.
- Fix dynamic server usage in app router docs endpoint by reading the headers from a cloned request object.
- Fix TS errors when using an async middleware.
- Export typings for
TypedNextRequest
,TypedNextApiRequest
andTypedNextApiResponse
so that they can be used for custom abstractions.
- Fix CLI commands causing ESBuild errors with third-party dependencies by parsing the OpenAPI specifications from the source code instead using
tsx
.
- Add support for validating path parameters separately from query parameters with pages router.
- Add support for validating path parameters with error responses for app router & using Zod-parsed path parameters.
- Add 10s form parsing timeout for pages router.
- Fix
req.json()
returning JSON serialized Zod-parsed request body instead of raw Zod-parsed body. - Fix RPC route response serialization for form data (app router and pages router) and File/Blob responses (pages router).
This is a breaking change that improves handling form data requests for both app router and pages router routes and RPC routes.
- Add support for strongly typed form data.
- Add support for overriding generated JSON schema with a custom JSON schema for request bodies, search params and response bodies.
- Add support for (strongly typed) form data for RPC routes.
- Rename response body schema in output objects from
schema
->body
for consistent naming conventions.
- Misc docs fixes.
- Fix CLI not finding config when using pages router and
src
folder.
- Fix
node_modules
being resolved by ESBuild when running the CLI commands withnpm
/npx
.
- Fix external dependency resolution causing the CLI commands not working for some users.
- Fix OpenAPI spec generation for query parameters.
- Fix RPC route returning an error when using a middleware with no input.
- Fix typings for asynchronous
routeOperation
/apiRouteOperation
middlewares.
- Fix custom HTTP responses from middleware functions not working with app router endpoints.
- Fix request body being parsed as
ReadableStream
instead of JSON when used in app router RPC endpoints.
- Remove additional console logs from the CLI commands.
- Add ESBuild external packages option to prevent any dependencies from being bundled as part of the CLI commands.
- Fix
__dirname
not defined duringnext build
with a custom ESBuild plugin.
- Remove all peer dependencies from the library causing a runtime import error.
- Fix runtime issue of Next.js modules not being imported correctly.
- Fix CLI commands not working on Windows due to incorrect file import URLs.
- Fix ESM bundling by defining
next
andzod
as peer dependencies and exclude them from the bundle. - Docs fixes.
- Add support for custom OG meta tags in the Redoc/SwaggerUI documentation.
- Fix bug of CLI not working when explicit ESM is set in
package.json
.
- Remove unneeded
tsConfigPath
option from CLI commands that is no longer needed.
TLDR: All Node.js API specific code is split
into the CLI which is much more reliable now.
Support for generating the OpenAPI spec automatically
when running the development server is dropped and
handled by the CLI command
npx next-rest-framework generate
instead.
This is a major change that simplifies the OpenAPI sepc generation process, and adds Edge runtime support.
This change completely removes the automatic local OpenAPI spec generation when calling the documentation endpoint and leaves the spec generation completely for the CLI which is now much more reliable for the following reason:
Previously the file system based OpenAPI
spec generation done by the CLI used the
build output generated by Next.js in the
.next
folder. This was however suboptimal
as there's no guarantee that the module
structure won't change between Next.js versions,
breaking the CLI. A new approach is that the
CLI commands generate
and validate
now
generate a temporary build folder called
.next-rest-framework
which is compiled using
ESBuild which produces consistent output from
the CLI. This temporary folder is used to gather
the OpenAPI paths from the generated routes
and api routes that works with all Next.js versions.
This is also much faster than running next build
every time with the CLI.
With this changes, all Node.js file system based API calls etc. are split do a different bundle so that the code also works in the Edge runtime.
- Fixed the ESM entry point causing NRF not being loaded as ESM.
- Fixed the possible return status codes from RPC routes to match the generated OpenAPI spec.
- Build the code for both ESM and CJS outputs using
tsup
.
- Add support for chaining up to three middlewares together and sharing data between the middlewares.
- Fix typings for optional additional OpenAPI properties that are merged with the generated document.
- Fix RPC data structure to merge in CLI commands.
Thanks to @roothybrid7 for the fix!
- Improve typings, OpenAPI generation, RPC logic and documentation. Rename several public APIs and deprecate the old ones:
docsRouteHandler
->docsRoute
routeHandler
->route
rpcRouteHandler
->rpcRoute
apiRouteHandler
->apiRoute
docsApiRouteHandler
->docsApiRoute
rpcApiRouteHandler
->rpcApiRoute
- Add support for creating RPC endpoints.
The output
function has been renamed to outputs
for clarity, simply renaming this will be enough for upgrading.
- Fix
prettier
import potentially causing a module resolution issue in some Node.js environments.
- Add CLI option to view additional logs for debugging purposes for the
generate
andvalidate
commands.
- Use content-relative URL for fetching the
openapi.json
in the docs clients.
- Fix OpenAPI generation with dynamic routes that contain multiple path parameters.
- Fix npm install not working on Windows.
- Fix TypedNextResponse usage.
- Add support for strongly-typed response content-type headers.
- Add support for strongly-typed NextResponse
- Add an option to include a middleware function for the method handlers, that gets executed before the request input is validated.
- Fix request handling when using a proxy or HTTPS connections locally.
- Add new
next-rest-framework validate
CLI command, that checks that the generatedopenapi.json
file is up to date.
- Improves the CLI performance, making it supported in any runtime.
- Overrides the OpenAPI info
title
anddescription
values with the docs config values when rendering the docs.
This is another breaking change before another major release. This mostly changes the API on creating new endpoints. The old object-based definition of API endpoints is replaced by a functional model, familiar from e.g. the trpc library.
The docs route handlers and route handler functions
are renamed, followed up with new utility function
used in conjunction with the new routeHandler
and
apiRouteHandler
functions. The new additional
routeOperation
(app router) and apiRouteOperation
(pages router) functions expose the same old API
including the input, output and handler definitions
in a slightly new format by chaining the oprations
after each other.
We also recently dropped SwaggerUI that was replaced by Redoc. This change allows the user to defined their desired docs frontend, bringing back the option to use SwaggerUI or even both Redoc and SwaggerUI at the same time.
This fixes the query parameter typings that were incorrect for both routers so that they are safer to use.
This also fixes duplicate inclusion of the parameters in the OpenAPI spec when using dynamic routes.
There are also some typings improvements for response
status codes, that we're not working previously.
Unfortunately, for app router the status codes are
still not limited to the user-defined response statuses,
because the NextResponse
API makes this impossible.
This fixes a bug that caused an infinite request loop when using pages router and the docs endpoint was not ignored by the OpenAPI path generation.
This fix also allows defining multiple different docs endpoints, although that should be a rare case. The request protocol parsing is also now handled differently with pages router and cases where the protocol headers contain multiple protocols should be handled now.
Improve DX, API docs, router compability etc.
This is another breaking change to multiple components of the framework, changing the client API, simplifying route definition etc.
Re-designed client API
Previously all features of the framework were available via single client, initialized by the user in their code base. This change removes the concept of initializing a client and accessing route definitions etc. via the client.
The documentation part is now decoupled from defining individual routes, meaning that the new simplified workflow allows the developer to define a single route for the generated documentation if they want it.
Individual routes can still be defined like before, without importing the route definitions from the client.
The documentation endpoint also does not have to be a catch-all route and it can be defined anywhere in the code base without breaking things.
In addition to having less boilerplate with the new
client API, we also get rid of configuring the paths
for the app
and pages
directories. The new smarter
approach handles this automatically by scanning these
folders automatically, detecting the src
directory
is in use.
Streamlined OpenAPI spec generation
Previously, we were storing the generated openapi.json
file in the root of the project and serving that via another
internal endpoint. The new approach simply generates the spec
file directly to the public
folder, where it will be served
for the API documentation.
Replacing SwaggerUI with Redoc
Redoc is a great open source project and replacement for SwaggerUI, offering more features like richer endpoint previews, search etc. The new rendered API documentation uses Redocly and it can still be configured and customized by the developer.
- Fix query parameter validation on app router - now the search parameters are validated similarly to when using pages router.
- Fix content type validation when no user-defined content type validation is set.
- Fix
appDirPath
handling when not using src directory.
- Fix miscellaneous issues with generating the OpenAPI spec from Zod schema, by using
zod-to-json-schema
.
- Fix request body validation with app router. The new validation clones the request object before validating it, allowing the request body to be further parsed by the API handler.
- Add option to allow/deny paths from Next REST Framework. This ensures better compability with other third-party server-side libraries and routes not using Next REST Framework.
- Add logging for error cases when the app/pages directory is not found based on the config options.
- Add logging for ignored paths based on the allow/deny lists.
- Fix pages router example code snippets in readme and docs pages.
- Fix an error of the pages directory not being found when only using pages router.
- Fix app router catch-all route documentation in the readme.
- Add support for dark theme in the SwaggerUI.
- Fixed an idempotency issue in the OpenAPI paths generation where the ordering of the generated paths was inconsistent between executions.
- Changed the OpenAPI spec generation to not make file system calls for API routes files when the config option
apiRoutesPath
is not defined.
Full details available in this PR: #49
- Add support for Next.js app router
- Remove support for global, route and method middlewares.
- Remove support for HTTP TRACE.
- Removed support for Node.js 16.
- Running
next-rest-framework generate
is no longer encouraged to be run together withnext build
.
- Drop support for Yup schemas in order to better support Zod that is the main object-schema validation library used with the framework.
- Add support for all applicable Zod schema types listed in their docs: https://zod.dev
- Fix path finding for windows environments, and add path parameters to OpenAPI spec.
- Fix miscellaneous bugs with Zod schemas, where
intersection
,nullable
andenum
types were not working with the OpenAPI spec generation.
- Add a binary script that can be used programmatically to generate the OpenAPI spec e.g. before running
next build
.
- Add SwaggerUI customization options for using custom title, description, logo and favicon.
- Fix bug that caused custom OpenAPI YAML file paths not working.
- Fix documentation and examples that were using Zod number schemas for query parameter validation, resulting in an error when following the examples.
- Revert the addition of the
localOpenApiSpec
config option. Using a user-defined route resulted in the generated OpenAPI spec file not being included in the Vercel build artifacts, thus making it not work. This issue is fixed by using a static path for the spec file so it will be always calledopenapi.json
and lies in the project root.
- Change OpenAPI generation by generating a local OpenAPI spec file that is dynamically updated in local development and used in production for the OpenAPI endpoints. Rename the
openApiSpec
config option toopenApiSpecOverrides
for better clarity with the addedlocalOpenApiSpec
path option.
- Fix bug with middlewares and error handlers that responded to the API request and the execution was not stopped.
- Fix the getting started docs containing a typo that caused an error.
- Fix the OpenAPI instrumentation for dynamic routes containing parameters that were not displayed correctly in the Swagger UI.
- Defining content type and request body are no longer required in the
input
object. Making the endpoint definition friendlier for different types of requests.
- Fix previous release not reflecting the latest changes introduced in the release notes of v0.3.6.
- Fix a bug that prevented nested API routes from being included into the OpenAPI spec.
- Fix content type header bug by removing the content type header parameters from the header validation logic. This caused e.g. form data requests to fail at runtime.
- Fix Zod/Yup typings so that both of those dependencies are no longer needed for using the framework.
- This fixes some compability issues with user-defined API routes that are not using Next REST Framework. There was a bug in the API route path matching where the comparison to the reserved paths was not exact, making some user-defined API routes to be completely skipped in some cases.
- Other fix here is that the instrumentation requests are now aborted after 200ms in case the user-defined APIs do not respond in that time.
- Add support for projects using a
src
folder with a new config option calledapiRoutesPath
.
- Change miscellaneous copyright texts and contact emails.
- Added support for typed query parameters. This changes the
input
object API by renaming theschema
attribute tobody
and adding aquery
attribute that can be used to type and validate query parameters for endpoints.
- Fixed an issue when using multiple output objects with different types - now the output types are combined with a union type to allow multiple different outputs.
Fix documentation on readme included with the NPM package.
- Changed the Swagger UI layout by adding a custom navbar and footer components.
- Changed the include Swagger UI by loading the assets from unpkg CDN and significantly reducing the bundle size.
- The public API is changed in a way that the OpenAPI spec generation is split out from the input/output validation. The validation is now done with
input
andoutput
keywords within thedefineEndpoints
handler, that generates a minimal OpenAPI spec out of the contents of the input and output definitions and all other OpenAPI generation-related overrides are done inside theopenApiSpec
object. This makes the separation of the business logic and documentation clearer, while still auto-generating the definitions from the application logic.
- Fix static URL that was used for API route instrumentation. The hardcoded value is now replaced with a dynamic value that should work in all environment. This change also caused the removal of the
getOpenApiSpec
function from the API. This is considered to be an API-breaking change but the early versions are not considered to be in use yet so it's safe to include it here.
- Fix NPM package not working due to CommonJS and ESM interoperability issue.
- Fix missing
summary
field from OpenAPI paths. - Fix miscellaneous typos in README.
- Add an example application with the installed NPM package.
- Added initial version of Next REST Framework.