Skip to content

Commit 55b3b25

Browse files
committed
chore(rest): make it clear that validation option is global for all parsers
1 parent 00ec6df commit 55b3b25

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

docs/site/Extending-request-body-parsing.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ the following configuration:
123123
text: {
124124
limit: '2MB'
125125
},
126-
// Validation options for AJV, see https://github.com/epoberezkin/ajv#options
127-
// This setting is global for all request body parsers.
126+
/**
127+
* Validation options for AJV, see https://github.com/epoberezkin/ajv#options
128+
* This setting is global for all request body parsers and it cannot be
129+
* overridden inside parser specific properties such as `json` or `text`.
130+
*/
128131
validation: {nullable: true},
129132
}
130133
```

packages/rest/src/__tests__/acceptance/validation/validation.acceptance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('Validation at REST level', () => {
119119
);
120120
after(() => app.stop());
121121

122-
it('rejects requests with `null` with {nullable: false}', async () => {
122+
it('rejects requests containing `null` with {nullable: false}', async () => {
123123
const DATA = {
124124
name: 'iPhone',
125125
description: null,

packages/rest/src/types.ts

+23
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,36 @@ export interface RequestBodyValidationOptions extends ajv.Options {
103103
/**
104104
* Options for request body parsing
105105
* See https://github.com/expressjs/body-parser/#options
106+
*
107+
* Built-in parsers retrieve their own options from the request body parser
108+
* options. The parser specific properties override common ones.
106109
*/
107110
export interface RequestBodyParserOptions extends Options {
111+
/**
112+
* Options for json parser
113+
*/
108114
json?: OptionsJson;
115+
/**
116+
* Options for urlencoded parser
117+
*/
109118
urlencoded?: OptionsUrlencoded;
119+
/**
120+
* Options for text parser
121+
*/
110122
text?: OptionsText;
123+
/**
124+
* Options for raw parser
125+
*/
111126
raw?: Options;
127+
/**
128+
* Validation options for AJV, see https://github.com/epoberezkin/ajv#options
129+
* This setting is global for all request body parsers and it cannot be
130+
* overridden inside parser specific properties such as `json` or `text`.
131+
*/
112132
validation?: RequestBodyValidationOptions;
133+
/**
134+
* Common options for all parsers
135+
*/
113136
[name: string]: unknown;
114137
}
115138

0 commit comments

Comments
 (0)