Skip to content

Commit

Permalink
docs: Update documentation about Catch decorator and Platform API
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Lenzotti committed Aug 31, 2020
1 parent c0e20cc commit 4cf49cb
Show file tree
Hide file tree
Showing 560 changed files with 4,806 additions and 5,289 deletions.
12 changes: 0 additions & 12 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ module.exports = {
}
],
sidebar: {
"/docs/middlewares/": [{
title: "Middlewares",
collapsable: false,
children: [
"call-sequence",
"override-middleware",
"override/authentication",
"override/global-error-handler",
"override/response-view",
"override/send-response"
]
}],
"/docs/": [
{
title: "Overview",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"api:build": "lerna run build && ts-doc",
"vuepress:build": "cross-env NODE_ENV=production vuepress build docs",
"vuepress:serve": "vuepress dev docs",
"prettier": "prettier '{src,test}/**/*.ts' --write",
"prettier": "prettier '{packages,test}/**/*.ts' --write",
"release": "semantic-release",
"release:dryRun": "semantic-release --dry-run"
},
Expand Down Expand Up @@ -137,7 +137,7 @@
"passport": "0.4.1",
"passport-local": "1.0.0",
"passport-strategy": "1.0.0",
"prettier": "1.19.1",
"prettier": "2.1.1",
"proxyquire": "2.1.3",
"semantic-release": "^15.13.18",
"sinon": "9.0.2",
Expand All @@ -153,7 +153,7 @@
"tslint": "6.1.3",
"type-graphql": "0.17.6",
"typeorm": "0.2.25",
"typescript": "3.8.3",
"typescript": "3.9.4",
"uuid": "3.3.3",
"vue-analytics": "5.22.1",
"vuepress": "1.5.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ajv/src/pipes/AjvErrorFormatterPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function defaultFormatter(error: AjvErrorObject, index: string | number) {
index !== undefined && error.modelName && isNaN(+index) && ".",
`${error.modelName || ""}`,
error.dataPath,
` ${error.message}. Given value: ${value}`
` ${error.message}. Given value: ${value}`,
]
// @ts-ignore
.filter<string>(Boolean)
Expand Down
92 changes: 39 additions & 53 deletions packages/ajv/src/pipes/AjvValidationPipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
QueryParams,
Required,
UseParam,
ValidationError
ValidationError,
} from "@tsed/common";
import {expect} from "chai";
import {AjvValidationPipe} from "./AjvValidationPipe";
Expand All @@ -32,17 +32,16 @@ describe("AjvValidationPipe", () => {
beforeEach(() =>
PlatformTest.create({
ajv: {
verbose: true
}
verbose: true,
},
})
);
afterEach(() => PlatformTest.reset());

describe("With raw json schema", () => {
it("should validate object", async () => {
class Ctrl {
get(@BodyParams() @UseSchema({type: "object"}) value: any) {
}
get(@BodyParams() @UseSchema({type: "object"}) value: any) {}
}

const value = {};
Expand All @@ -52,8 +51,7 @@ describe("AjvValidationPipe", () => {
});
it("should throw an error", async () => {
class Ctrl {
get(@BodyParams() @UseSchema({type: "object"}) value: any) {
}
get(@BodyParams() @UseSchema({type: "object"}) value: any) {}
}

const value: any[] = [];
Expand All @@ -68,31 +66,29 @@ describe("AjvValidationPipe", () => {
keyword: "type",
message: "should be object",
params: {
type: "object"
type: "object",
},
parentSchema: {
type: "object"
type: "object",
},
schema: "object",
schemaPath: "#/type"
}
schemaPath: "#/type",
},
]);
});
});
describe("With String", () => {
it("should validate value", async () => {
class Ctrl {
get(@BodyParams() value: string) {
}
get(@BodyParams() value: string) {}
}

const metadata = ParamMetadata.get(Ctrl, "get", 0);
expect(await validate("test", metadata)).to.deep.equal("test");
});
it("should validate value (array)", async () => {
class Ctrl {
get(@BodyParams({useType: String}) value: string[]) {
}
get(@BodyParams({useType: String}) value: string[]) {}
}

const metadata = ParamMetadata.get(Ctrl, "get", 0);
Expand All @@ -102,8 +98,7 @@ describe("AjvValidationPipe", () => {
describe("With QueryParam with boolean", () => {
it("should validate value", async () => {
class Ctrl {
get(@QueryParams("test") value: boolean) {
}
get(@QueryParams("test") value: boolean) {}
}

const metadata = ParamMetadata.get(Ctrl, "get", 0);
Expand All @@ -122,12 +117,11 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY) value: Model) {
}
get(@UseParam(ParamTypes.BODY) value: Model) {}
}

const value = {
id: "hello"
id: "hello",
};
const result = await validate(value, ParamMetadata.get(Ctrl, "get", 0));

Expand All @@ -141,8 +135,7 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY) value: Model) {
}
get(@UseParam(ParamTypes.BODY) value: Model) {}
}

const value: any = {};
Expand All @@ -160,25 +153,25 @@ describe("AjvValidationPipe", () => {
message: "should have required property 'id'",
modelName: "Model",
params: {
missingProperty: "id"
missingProperty: "id",
},
parentSchema: {
definitions: {},
properties: {
id: {
type: "string"
}
type: "string",
},
},
required: ["id"],
type: "object"
type: "object",
},
schema: {
id: {
type: "string"
}
type: "string",
},
},
schemaPath: "#/required"
}
schemaPath: "#/required",
},
]);
});
it("should throw an error (deep property)", async () => {
Expand All @@ -196,13 +189,12 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY) value: Model) {
}
get(@UseParam(ParamTypes.BODY) value: Model) {}
}

const value: any = {
id: "id",
user: {}
user: {},
};

const error = await validate(value, ParamMetadata.get(Ctrl, "get", 0));
Expand All @@ -221,14 +213,13 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {}
}

const value = [
{
id: "hello"
}
id: "hello",
},
];
const result = await validate(value, ParamMetadata.get(Ctrl, "get", 0));

Expand All @@ -242,8 +233,7 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {}
}

const value: any = [{}];
Expand All @@ -269,15 +259,14 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Model[]) {}
}

const value: any = [
{
id: "id",
user: {}
}
user: {},
},
];

const error = await validate(value, ParamMetadata.get(Ctrl, "get", 0));
Expand All @@ -296,14 +285,13 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {}
}

const value = {
key1: {
id: "hello"
}
id: "hello",
},
};
const result = await validate(value, ParamMetadata.get(Ctrl, "get", 0));

Expand All @@ -317,8 +305,7 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {}
}

const value: any = {key1: {}};
Expand All @@ -344,15 +331,14 @@ describe("AjvValidationPipe", () => {
}

class Ctrl {
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {
}
get(@UseParam(ParamTypes.BODY, {useType: Model}) value: Map<string, Model>) {}
}

const value: any = {
key1: {
id: "id",
user: {}
}
user: {},
},
};

const error = await validate(value, ParamMetadata.get(Ctrl, "get", 0));
Expand Down
2 changes: 1 addition & 1 deletion packages/ajv/src/pipes/AjvValidationPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class AjvValidationPipe extends ValidationPipe implements IPipe {
const options = {
ignoreCallback: (obj: any, type: any) => type === Date,
checkRequiredValue: false,
additionalProperties: metadata.paramType === ParamTypes.QUERY ? "ignore" : undefined
additionalProperties: metadata.paramType === ParamTypes.QUERY ? "ignore" : undefined,
};

if (metadata.isCollection) {
Expand Down
10 changes: 5 additions & 5 deletions packages/ajv/src/services/Ajv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe("Ajv", () => {
expect(
ajv.validate(
{
type: "object"
type: "object",
},
{}
)
).to.equal(true);

ajv.validate(
{
type: "object"
type: "object",
},
[]
);
Expand All @@ -32,10 +32,10 @@ describe("Ajv", () => {
keyword: "type",
message: "should be object",
params: {
type: "object"
type: "object",
},
schemaPath: "#/type"
}
schemaPath: "#/type",
},
]);
});
});
4 changes: 2 additions & 2 deletions packages/ajv/src/services/Ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ registerProvider({
return new Ajv({
verbose: false,
...props,
...options
...options,
});
}
},
});

0 comments on commit 4cf49cb

Please sign in to comment.