All notable changes to this project will be documented in this file. We follow the Semantic Versioning 2.0.0 format.
- 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 Route 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: blomqma#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.