Skip to content

VERSION_NEUTRAL

reference
1 min readUpdated

Kind: Constant

Source: packages/common/interfaces/version-options.interface.ts

Part of: Common

Indicates that this will work for any version passed in the request, or no version.

VERSION_NEUTRAL is a versioning constant that marks a route or controller as compatible with every API version. It allows an endpoint to handle requests regardless of whether a version is specified in the request, providing a fallback for version-neutral functionality.

Definition

ts
Symbol('VERSION_NEUTRAL')

Value

ts
Symbol('VERSION_NEUTRAL')

Diagram

mermaid
graph LR
  Request[Incoming Request] --> VersionCheck{Version specified?}
  VersionCheck -->|Yes| VersionedRoute[Version-specific Route]
  VersionCheck -->|No or Any Version| NeutralRoute[VERSION_NEUTRAL Route]
  NeutralRoute --> Handler[Route Handler]

Usage

ts
import { Controller, Get, VERSION_NEUTRAL } from '@nestjs/common';

@Controller({
  path: 'health',
  version: VERSION_NEUTRAL,
})
export class HealthController {
  @Get()
  check() {
    return { status: 'ok' };
  }
}

AI Coding Instructions

  • Use VERSION_NEUTRAL for endpoints that must remain accessible across all API versions, such as health checks or shared metadata routes.
  • Apply it through controller or route version metadata where Nest versioning is enabled.
  • Do not use it for endpoints whose response contract changes between API versions.
  • Ensure version-neutral routes do not conflict with version-specific routes using the same HTTP method and path.
  • Test requests both with and without version information to confirm the route is resolved as expected.

Used by

7 references from 7 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (7)

  • RoutePathFactorypackages/core/router/route-path-factory.ts:18
  • VersionNeutralMiddlewareControllerintegration/versioning/src/neutral-middleware.controller.ts:3
  • VersionNeutralControllerintegration/versioning/src/neutral.controller.ts:3
  • modulesContainerpackages/core/middleware/routes-mapper.ts:148
  • MODULE_INIT_MESSAGEpackages/core/helpers/messages.ts:7
  • ExpressAdapterpackages/platform-express/adapters/express-adapter.ts:51
  • FastifyAdapterpackages/platform-fastify/adapters/fastify-adapter.ts:124

Was this page helpful?

Download as PDF
VERSION_NEUTRAL — NestJS head-to-head