@@ -2,16 +2,18 @@ import {
22 HOST_METADATA ,
33 PATH_METADATA ,
44 SCOPE_OPTIONS_METADATA ,
5+ VERSION_METADATA ,
56} from '../../constants' ;
67import { ScopeOptions } from '../../interfaces/scope-options.interface' ;
8+ import { VersionOptions } from '../../interfaces/version-options.interface' ;
79import { isString , isUndefined } from '../../utils/shared.utils' ;
810
911/**
1012 * Interface defining options that can be passed to `@Controller()` decorator
1113 *
1214 * @publicApi
1315 */
14- export interface ControllerOptions extends ScopeOptions {
16+ export interface ControllerOptions extends ScopeOptions , VersionOptions {
1517 /**
1618 * Specifies an optional `route path prefix`. The prefix is pre-pended to the
1719 * path specified in any request decorator in the class.
@@ -97,10 +99,14 @@ export function Controller(prefix: string | string[]): ClassDecorator;
9799 * more details.
98100 * - `prefix` - string that defines a `route path prefix`. The prefix
99101 * is pre-pended to the path specified in any request decorator in the class.
102+ * - `version` - string, array of strings, or Symbol that defines the version
103+ * of all routes in the class. [See Versioning](https://docs.nestjs.com/techniques/versioning)
104+ * for more details.
100105 *
101106 * @see [Routing](https://docs.nestjs.com/controllers#routing)
102107 * @see [Controllers](https://docs.nestjs.com/controllers)
103108 * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
109+ * @see [Versioning](https://docs.nestjs.com/techniques/versioning)
104110 *
105111 * @publicApi
106112 */
@@ -128,11 +134,15 @@ export function Controller(options: ControllerOptions): ClassDecorator;
128134 * more details.
129135 * - `prefix` - string that defines a `route path prefix`. The prefix
130136 * is pre-pended to the path specified in any request decorator in the class.
137+ * - `version` - string, array of strings, or Symbol that defines the version
138+ * of all routes in the class. [See Versioning](https://docs.nestjs.com/techniques/versioning)
139+ * for more details.
131140 *
132141 * @see [Routing](https://docs.nestjs.com/controllers#routing)
133142 * @see [Controllers](https://docs.nestjs.com/controllers)
134143 * @see [Microservices](https://docs.nestjs.com/microservices/basics#request-response)
135144 * @see [Scope](https://docs.nestjs.com/fundamentals/injection-scopes#usage)
145+ * @see [Versioning](https://docs.nestjs.com/techniques/versioning)
136146 *
137147 * @publicApi
138148 */
@@ -141,19 +151,23 @@ export function Controller(
141151) : ClassDecorator {
142152 const defaultPath = '/' ;
143153
144- const [ path , host , scopeOptions ] = isUndefined ( prefixOrOptions )
145- ? [ defaultPath , undefined , undefined ]
154+ const [ path , host , scopeOptions , versionOptions ] = isUndefined (
155+ prefixOrOptions ,
156+ )
157+ ? [ defaultPath , undefined , undefined , undefined ]
146158 : isString ( prefixOrOptions ) || Array . isArray ( prefixOrOptions )
147- ? [ prefixOrOptions , undefined , undefined ]
159+ ? [ prefixOrOptions , undefined , undefined , undefined ]
148160 : [
149161 prefixOrOptions . path || defaultPath ,
150162 prefixOrOptions . host ,
151163 { scope : prefixOrOptions . scope } ,
164+ prefixOrOptions . version ,
152165 ] ;
153166
154167 return ( target : object ) => {
155168 Reflect . defineMetadata ( PATH_METADATA , path , target ) ;
156169 Reflect . defineMetadata ( HOST_METADATA , host , target ) ;
157170 Reflect . defineMetadata ( SCOPE_OPTIONS_METADATA , scopeOptions , target ) ;
171+ Reflect . defineMetadata ( VERSION_METADATA , versionOptions , target ) ;
158172 } ;
159173}
0 commit comments