diff --git a/packages/platform/platform-params/src/decorators/pathParams.spec.ts b/packages/platform/platform-params/src/decorators/pathParams.spec.ts index bdecd079e26..309e735d94d 100644 --- a/packages/platform/platform-params/src/decorators/pathParams.spec.ts +++ b/packages/platform/platform-params/src/decorators/pathParams.spec.ts @@ -1,6 +1,6 @@ +import {JsonParameterStore} from "@tsed/schema"; import {ParamTypes} from "../domain/ParamTypes"; import {PathParams, RawPathParams} from "./pathParams"; -import {JsonParameterStore} from "@tsed/schema"; describe("@PathParams", () => { it("should call ParamFilter.useParam method with the correct parameters", () => { @@ -14,6 +14,20 @@ describe("@PathParams", () => { expect(param.expression).toEqual("expression"); expect(param.paramType).toEqual(ParamTypes.PATH); expect(param.type).toEqual(Test); + expect(param.pipes).toHaveLength(2); + }); + it("should call ParamFilter.useParam method with the correct parameters (+options)", () => { + class Test {} + + class Ctrl { + test(@PathParams({expression: "expression", useType: Test, useValidation: false}) param: Test) {} + } + + const param = JsonParameterStore.get(Ctrl, "test", 0); + expect(param.expression).toEqual("expression"); + expect(param.paramType).toEqual(ParamTypes.PATH); + expect(param.type).toEqual(Test); + expect(param.pipes).toHaveLength(1); }); it("should call ParamFilter.useParam method with the correct parameters (raw)", () => { class Ctrl { @@ -23,5 +37,18 @@ describe("@PathParams", () => { const param = JsonParameterStore.get(Ctrl, "test", 0); expect(param.expression).toEqual("expression"); expect(param.paramType).toEqual(ParamTypes.PATH); + expect(param.type).toEqual(String); + expect(param.pipes).toHaveLength(0); + }); + it("should call ParamFilter.useParam method with the correct parameters (raw + options)", () => { + class Ctrl { + test(@RawPathParams({expression: "expression", useValidation: true, useType: String}) param: Date) {} + } + + const param = JsonParameterStore.get(Ctrl, "test", 0); + expect(param.expression).toEqual("expression"); + expect(param.paramType).toEqual(ParamTypes.PATH); + expect(param.type).toEqual(String); + expect(param.pipes).toHaveLength(1); }); }); diff --git a/packages/platform/platform-params/src/decorators/pathParams.ts b/packages/platform/platform-params/src/decorators/pathParams.ts index e77c746c020..e279b2f813b 100644 --- a/packages/platform/platform-params/src/decorators/pathParams.ts +++ b/packages/platform/platform-params/src/decorators/pathParams.ts @@ -81,10 +81,17 @@ export function PathParams(...args: any[]): ParameterDecorator { * @operation * @input */ -export function RawPathParams(expression: string) { +export function RawPathParams(expression: string): ParameterDecorator; +export function RawPathParams(options: Partial): ParameterDecorator; +export function RawPathParams(): ParameterDecorator; +export function RawPathParams(...args: any[]): ParameterDecorator { + const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args); return UseParam({ paramType: ParamTypes.PATH, dataPath: "$ctx.request.params", - expression + expression, + useValidation, + useMapper, + useType }); } diff --git a/packages/platform/platform-params/src/pipes/DeserializerPipe.ts b/packages/platform/platform-params/src/pipes/DeserializerPipe.ts index 17eff02b0be..b4676259ebb 100644 --- a/packages/platform/platform-params/src/pipes/DeserializerPipe.ts +++ b/packages/platform/platform-params/src/pipes/DeserializerPipe.ts @@ -1,4 +1,4 @@ -import {Constant, Injectable} from "@tsed/di"; +import {Injectable} from "@tsed/di"; import {deserialize} from "@tsed/json-mapper"; import {JsonParameterStore, PipeMethods} from "@tsed/schema";