Skip to content

Commit dd4f710

Browse files
committed
Rename @param(s) decorators to @PathParam(s)
1 parent fb18b54 commit dd4f710

File tree

17 files changed

+64
-64
lines changed

17 files changed

+64
-64
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].
128128
}
129129
130130
@Get("/users/:id")
131-
getOne(@Param("id") id: number) {
131+
getOne(@PathParam("id") id: number) {
132132
return "This action returns user #" + id;
133133
}
134134
@@ -138,12 +138,12 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].
138138
}
139139
140140
@Put("/users/:id")
141-
put(@Param("id") id: number, @Body() user: any) {
141+
put(@PathParam("id") id: number, @Body() user: any) {
142142
return "Updating a user...";
143143
}
144144
145145
@Delete("/users/:id")
146-
remove(@Param("id") id: number) {
146+
remove(@PathParam("id") id: number) {
147147
return "Removing user...";
148148
}
149149
@@ -195,7 +195,7 @@ export class UserController {
195195
}
196196
197197
@Get("/users/:id")
198-
getOne(@Param("id") id: number) {
198+
getOne(@PathParam("id") id: number) {
199199
return userRepository.findById(id);
200200
}
201201
@@ -222,7 +222,7 @@ export class UserController {
222222
}
223223
224224
@Get("/users/:id")
225-
getOne(@Param("id") id: number) {
225+
getOne(@PathParam("id") id: number) {
226226
return userRepository.findById(id);
227227
}
228228
@@ -232,12 +232,12 @@ export class UserController {
232232
}
233233
234234
@Put("/users/:id")
235-
put(@Param("id") id: number, @Body() user: User) {
235+
put(@PathParam("id") id: number, @Body() user: User) {
236236
return userRepository.updateById(id, user);
237237
}
238238
239239
@Delete("/users/:id")
240-
remove(@Param("id") id: number) {
240+
remove(@PathParam("id") id: number) {
241241
return userRepository.removeById(id);
242242
}
243243
@@ -346,15 +346,15 @@ export class UserController {
346346

347347
#### Inject routing parameters
348348

349-
You can use `@Param` decorator to inject parameters in your controller actions:
349+
You can use `@PathParam` decorator to inject parameters in your controller actions:
350350

351351
```typescript
352352
@Get("/users/:id")
353-
getOne(@Param("id") id: number) { // id will be automatically casted to "number" because it has type number
353+
getOne(@PathParam("id") id: number) { // id will be automatically casted to "number" because it has type number
354354
}
355355
```
356356

357-
If you want to inject all parameters use `@Params()` decorator.
357+
If you want to inject all parameters use `@PathParams()` decorator.
358358

359359
#### Inject query parameters
360360

@@ -615,7 +615,7 @@ To prevent this if you need to specify what status code you want to return using
615615
```typescript
616616
@Delete("/users/:id")
617617
@OnUndefined(204)
618-
async remove(@Param("id") id: number): Promise<void> {
618+
async remove(@PathParam("id") id: number): Promise<void> {
619619
return userRepository.removeById(id);
620620
}
621621
```
@@ -627,7 +627,7 @@ This action will return 404 in the case if user was not found, and regular 200 i
627627
```typescript
628628
@Get("/users/:id")
629629
@OnUndefined(404)
630-
getOne(@Param("id") id: number) {
630+
getOne(@PathParam("id") id: number) {
631631
return userRepository.findOneById(id);
632632
}
633633
```
@@ -647,7 +647,7 @@ export class UserNotFoundError extends HttpError {
647647
```typescript
648648
@Get("/users/:id")
649649
@OnUndefined(UserNotFoundError)
650-
saveUser(@Param("id") id: number) {
650+
saveUser(@PathParam("id") id: number) {
651651
return userRepository.findOneById(id);
652652
}
653653
```
@@ -661,7 +661,7 @@ You can set any custom header in a response:
661661
```typescript
662662
@Get("/users/:id")
663663
@Header("Cache-Control", "none")
664-
getOne(@Param("id") id: number) {
664+
getOne(@PathParam("id") id: number) {
665665
// ...
666666
}
667667
```
@@ -691,7 +691,7 @@ If you want to return errors with specific error codes, there is an easy way:
691691

692692
```typescript
693693
@Get("/users/:id")
694-
getOne(@Param("id") id: number) {
694+
getOne(@PathParam("id") id: number) {
695695

696696
const user = this.userRepository.findOneById(id);
697697
if (!user)
@@ -810,7 +810,7 @@ For example, lets try to use [compression](https://github.com/expressjs/compress
810810

811811
@Get("/users/:id")
812812
@UseBefore(compression())
813-
getOne(@Param("id") id: number) {
813+
getOne(@PathParam("id") id: number) {
814814
// ...
815815
}
816816
```
@@ -902,7 +902,7 @@ Here is example of creating middleware for express.js:
902902
@Get("/users/:id")
903903
@UseBefore(MyMiddleware)
904904
@UseAfter(loggingMiddleware)
905-
getOne(@Param("id") id: number) {
905+
getOne(@PathParam("id") id: number) {
906906
// ...
907907
}
908908
```
@@ -969,7 +969,7 @@ Here is example of creating middleware for koa.js:
969969
@Get("/users/:id")
970970
@UseBefore(MyMiddleware)
971971
@UseAfter(loggingMiddleware)
972-
getOne(@Param("id") id: number) {
972+
getOne(@PathParam("id") id: number) {
973973
// ...
974974
}
975975
```
@@ -1075,7 +1075,7 @@ import {Get, Param, UseInterceptor} from "routing-controllers";
10751075
// in it and return a replaced result. replaced result will be returned to the user
10761076
return content.replace(/Mike/gi, "Michael");
10771077
})
1078-
getOne(@Param("id") id: number) {
1078+
getOne(@PathParam("id") id: number) {
10791079
return "Hello, I am Mike!"; // client will get a "Hello, I am Michael!" response.
10801080
}
10811081
```
@@ -1109,7 +1109,7 @@ import {NameCorrectionInterceptor} from "./NameCorrectionInterceptor";
11091109

11101110
@Get("/users")
11111111
@UseInterceptor(NameCorrectionInterceptor)
1112-
getOne(@Param("id") id: number) {
1112+
getOne(@PathParam("id") id: number) {
11131113
return "Hello, I am Mike!"; // client will get a "Hello, I am Michael!" response.
11141114
}
11151115
```
@@ -1173,7 +1173,7 @@ export class UserController {
11731173
If `User` is an interface - then simple literal object will be created.
11741174
If its a class - then instance of this class will be created.
11751175

1176-
This technique works not only with `@Body`, but also with `@Param`, `@QueryParam`, `@BodyParam` and other decorators.
1176+
This technique works not only with `@Body`, but also with `@PathParam`, `@QueryParam`, `@BodyParam` and other decorators.
11771177
Learn more about class-transformer and how to handle more complex object constructions [here][4].
11781178
This behaviour is enabled by default.
11791179
If you want to disable it simply pass `classTransformer: false` to createExpressServer method.
@@ -1234,7 +1234,7 @@ an error will be thrown and captured by routing-controller, so the client will r
12341234
12351235
If you need special options for validation (groups, skipping missing properties, etc.) or transforming (groups, excluding prefixes, versions, etc.), you can pass them as global config as `validation ` in createExpressServer method or as a local `validate` setting for method parameter - `@Body({ validate: localOptions })`.
12361236
1237-
This technique works not only with `@Body` but also with `@Param`, `@QueryParam`, `@BodyParam` and other decorators.
1237+
This technique works not only with `@Body` but also with `@PathParam`, `@QueryParam`, `@BodyParam` and other decorators.
12381238
12391239
## Using authorization features
12401240
@@ -1428,8 +1428,8 @@ export class QuestionController {
14281428
| `@Req()` | `getAll(@Req() request: Request)` | Injects a Request object. | `function (request, response)` |
14291429
| `@Res()` | `getAll(@Res() response: Response)` | Injects a Response object. | `function (request, response)` |
14301430
| `@Ctx()` | `getAll(@Ctx() context: Context)` | Injects a Context object (koa-specific) | `function (ctx)` (koa-analogue) |
1431-
| `@Param(name: string, options?: ParamOptions)` | `get(@Param("id") id: number)` | Injects a router parameter. | `request.params.id` |
1432-
| `@Params()` | `get(@Params() params: any)` | Injects all request parameters. | `request.params` |
1431+
| `@PathParam(name: string, options?: ParamOptions)` | `get(@PathParam("id") id: number)` | Injects a router parameter. | `request.params.id` |
1432+
| `@PathParams()` | `get(@PathParams() params: any)` | Injects all request parameters. | `request.params` |
14331433
| `@QueryParam(name: string, options?: ParamOptions)` | `get(@QueryParam("id") id: number)` | Injects a query string parameter. | `request.query.id` |
14341434
| `@QueryParams()` | `get(@QueryParams() params: any)` | Injects all query parameters. | `request.query` |
14351435
| `@HeaderParam(name: string, options?: ParamOptions)` | `get(@HeaderParam("token") token: string)` | Injects a specific request headers. | `request.headers.token` |

sample/sample11-complete-sample-express/modules/question/controllers/QuestionController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Request} from "express";
22
import {JsonController} from "../../../../../src/decorator/JsonController";
33
import {Get} from "../../../../../src/decorator/Get";
4-
import {Param} from "../../../../../src/decorator/Param";
4+
import {PathParam} from "../../../../../src/decorator/PathParam";
55
import {Post} from "../../../../../src/decorator/Post";
66
import {Req} from "../../../../../src/decorator/Req";
77
import {Put} from "../../../../../src/decorator/Put";
@@ -20,7 +20,7 @@ export class QuestionController {
2020
}
2121

2222
@Get("/questions/:id")
23-
getOne(@Param("id") id: number) {
23+
getOne(@PathParam("id") id: number) {
2424
if (!id)
2525
return Promise.reject(new Error("No id is specified"));
2626

sample/sample12-session-support/UserController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Post} from "../../src/decorator/Post";
77
import {Put} from "../../src/decorator/Put";
88
import {Patch} from "../../src/decorator/Patch";
99
import {Delete} from "../../src/decorator/Delete";
10-
import {Param} from "../../src/decorator/Param";
10+
import {PathParam} from "../../src/decorator/PathParam";
1111
import {Session} from "../../src/decorator/Session";
1212
import {ContentType} from "../../src/decorator/ContentType";
1313

@@ -36,7 +36,7 @@ export class UserController {
3636
}
3737

3838
@Put("/users/:id")
39-
put(@Param("id") id: number, @Session() session: Express.Session) {
39+
put(@PathParam("id") id: number, @Session() session: Express.Session) {
4040
(session as any).user = { name: "test", number: id };
4141
return "User has been putted!";
4242
}

sample/sample4-extra-parameters/BlogController.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Put} from "../../src/decorator/Put";
55
import {Patch} from "../../src/decorator/Patch";
66
import {Delete} from "../../src/decorator/Delete";
77
import {QueryParam} from "../../src/decorator/QueryParam";
8-
import {Param} from "../../src/decorator/Param";
8+
import {PathParam} from "../../src/decorator/PathParam";
99
import {Body} from "../../src/decorator/Body";
1010

1111
export interface BlogFilter {
@@ -26,7 +26,7 @@ export class BlogController {
2626
}
2727

2828
@Get("/blogs/:id")
29-
getOne(@Param("id") id: number, @QueryParam("name") name: string) {
29+
getOne(@PathParam("id") id: number, @QueryParam("name") name: string) {
3030
return { id: id, name: name };
3131
}
3232

@@ -36,17 +36,17 @@ export class BlogController {
3636
}
3737

3838
@Put("/blogs/:id")
39-
put(@Param("id") id: number) {
39+
put(@PathParam("id") id: number) {
4040
return "Blog #" + id + " has been putted!";
4141
}
4242

4343
@Patch("/blogs/:id")
44-
patch(@Param("id") id: number) {
44+
patch(@PathParam("id") id: number) {
4545
return "Blog #" + id + " has been patched!";
4646
}
4747

4848
@Delete("/blogs/:id")
49-
remove(@Param("id") id: number) {
49+
remove(@PathParam("id") id: number) {
5050
return "Blog #" + id + " has been removed!";
5151
}
5252

sample/sample6-global-middlewares/BlogController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ForbiddenError} from "../../src/http-error/ForbiddenError";
22
import {Controller} from "../../src/decorator/Controller";
33
import {Get} from "../../src/decorator/Get";
4-
import {Param} from "../../src/decorator/Param";
4+
import {PathParam} from "../../src/decorator/PathParam";
55
import {ContentType} from "../../src/decorator/ContentType";
66

77
@Controller()
@@ -19,7 +19,7 @@ export class BlogController {
1919

2020
@Get("/blogs/:id")
2121
@ContentType("application/json")
22-
getOne(@Param("id") id: number) {
22+
getOne(@PathParam("id") id: number) {
2323
if (!id)
2424
throw new ForbiddenError();
2525

sample/sample9-use-and-middlewares/BlogController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {JsonController} from "../../src/decorator/JsonController";
22
import {Get} from "../../src/decorator/Get";
3-
import {Param} from "../../src/decorator/Param";
3+
import {PathParam} from "../../src/decorator/PathParam";
44
import {CompressionMiddleware} from "./CompressionMiddleware";
55
import {AllControllerActionsMiddleware} from "./AllControllerActionsMiddleware";
66
import {UseBefore} from "../../src/decorator/UseBefore";
@@ -24,7 +24,7 @@ export class BlogController {
2424
}
2525

2626
@Get("/blogs/:id")
27-
getOne(@Param("id") id: number) {
27+
getOne(@PathParam("id") id: number) {
2828
return { id: id, firstName: "First", secondName: "blog" };
2929
}
3030

src/ActionParameterHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
110110
return value;
111111

112112
// if param value is an object and param type match, normalize its string properties
113-
if (typeof value === "object" && ["queries", "headers", "params", "cookies"].indexOf(param.type) !== -1) {
113+
if (typeof value === "object" && ["queries", "headers", "path-params", "cookies"].indexOf(param.type) !== -1) {
114114
Object.keys(value).map(key => {
115115
const keyValue = (value as any)[key];
116116
if (typeof keyValue === "string") {

src/decorator/Param.ts renamed to src/decorator/PathParam.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {getMetadataArgsStorage} from "../index";
44
* Injects a request's route parameter value to the controller action parameter.
55
* Must be applied on a controller action parameter.
66
*/
7-
export function Param(name: string): Function {
7+
export function PathParam(name: string): Function {
88
return function (object: Object, methodName: string, index: number) {
99
getMetadataArgsStorage().params.push({
10-
type: "param",
10+
type: "path-param",
1111
object: object,
1212
method: methodName,
1313
index: index,

src/decorator/Params.ts renamed to src/decorator/PathParams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {getMetadataArgsStorage} from "../index";
55
* Injects all request's route parameters to the controller action parameter.
66
* Must be applied on a controller action parameter.
77
*/
8-
export function Params(options?: ParamOptions): Function {
8+
export function PathParams(options?: ParamOptions): Function {
99
return function (object: Object, methodName: string, index: number) {
1010
getMetadataArgsStorage().params.push({
11-
type: "params",
11+
type: "path-params",
1212
object: object,
1313
method: methodName,
1414
index: index,

src/driver/express/ExpressDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ export class ExpressDriver extends BaseDriver {
181181
case "body-param":
182182
return request.body[param.name];
183183

184-
case "param":
184+
case "path-param":
185185
return request.params[param.name];
186186

187-
case "params":
187+
case "path-params":
188188
return request.params;
189189

190190
case "session":

src/driver/koa/KoaDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ export class KoaDriver extends BaseDriver {
163163
case "body-param":
164164
return request.body[param.name];
165165

166-
case "param":
166+
case "path-param":
167167
return context.params[param.name];
168168

169-
case "params":
169+
case "path-params":
170170
return context.params;
171171

172172
case "session":

src/error/ParamRequiredError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export class ParamRequiredError extends BadRequestError {
1515

1616
let paramName: string;
1717
switch (param.type) {
18-
case "param":
19-
paramName = `Parameter "${param.name}" is`;
18+
case "path-param":
19+
paramName = `Path parameter "${param.name}" is`;
2020
break;
2121

2222
case "body":

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export * from "./decorator/Method";
3737
export * from "./decorator/Middleware";
3838
export * from "./decorator/OnNull";
3939
export * from "./decorator/OnUndefined";
40-
export * from "./decorator/Param";
41-
export * from "./decorator/Params";
40+
export * from "./decorator/PathParam";
41+
export * from "./decorator/PathParams";
4242
export * from "./decorator/Patch";
4343
export * from "./decorator/Post";
4444
export * from "./decorator/Put";

src/metadata/types/ParamType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export type ParamType = "body"
99
|"headers"
1010
|"file"
1111
|"files"
12-
|"param"
13-
|"params"
12+
|"path-param"
13+
|"path-params"
1414
|"session"
1515
|"state"
1616
|"cookie"

0 commit comments

Comments
 (0)