Skip to content

Commit f9ce2b2

Browse files
fix: schema description (#783)
1 parent 7973be9 commit f9ce2b2

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

README.md

+9-15
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The middleware accepts an `options` Object. The following is a property referenc
6666
Type: `Array`
6767
Default: `[ 'GET', 'HEAD' ]`
6868

69-
This property allows a user to pass the list of HTTP request methods accepted by the server.
69+
This property allows a user to pass the list of HTTP request methods accepted by the middleware\*\*.
7070

7171
### headers
7272

@@ -107,26 +107,20 @@ For more information about `publicPath`, please see [the webpack documentation](
107107
Type: `Boolean`
108108
Default: `undefined`
109109

110-
Instructs the module to enable or disable the server-side rendering mode. Please
111-
see [Server-Side Rendering](#server-side-rendering) for more information.
110+
Instructs the module to enable or disable the server-side rendering mode.
111+
Please see [Server-Side Rendering](#server-side-rendering) for more information.
112112

113113
### writeToDisk
114114

115115
Type: `Boolean|Function`
116116
Default: `false`
117117

118-
If `true`, the option will instruct the module to write files to the configured
119-
location on disk as specified in your `webpack` config file. _Setting
120-
`writeToDisk: true` won't change the behavior of the `webpack-dev-middleware`,
121-
and bundle files accessed through the browser will still be served from memory._
122-
This option provides the same capabilities as the
123-
[`WriteFilePlugin`](https://github.com/gajus/write-file-webpack-plugin/pulls).
124-
125-
This option also accepts a `Function` value, which can be used to filter which
126-
files are written to disk. The function follows the same premise as
127-
[`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
128-
in which a return value of `false` _will not_ write the file, and a return value
129-
of `true` _will_ write the file to disk. eg.
118+
If `true`, the option will instruct the module to write files to the configured location on disk as specified in your `webpack` config file.
119+
_Setting `writeToDisk: true` won't change the behavior of the `webpack-dev-middleware`, and bundle files accessed through the browser will still be served from memory._
120+
This option provides the same capabilities as the [`WriteFilePlugin`](https://github.com/gajus/write-file-webpack-plugin/pulls).
121+
122+
This option also accepts a `Function` value, which can be used to filter which files are written to disk.
123+
The function follows the same premise as [`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) in which a return value of `false` _will not_ write the file, and a return value of `true` _will_ write the file to disk. eg.
130124

131125
```js
132126
const webpack = require('webpack');

src/options.json

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"type": "object",
33
"properties": {
44
"mimeTypes": {
5+
"description": "Allows a user to register custom mime types or extension mappings.",
56
"type": "object"
67
},
78
"writeToDisk": {
9+
"description": "Allows to write generated files on disk.",
810
"anyOf": [
911
{
1012
"type": "boolean"
@@ -15,30 +17,47 @@
1517
]
1618
},
1719
"methods": {
20+
"description": "Allows to pass the list of HTTP request methods accepted by the middleware.",
1821
"type": "array",
1922
"items": {
20-
"type": "string"
23+
"type": "string",
24+
"minlength": "1"
2125
}
2226
},
2327
"headers": {
2428
"type": "object"
2529
},
2630
"publicPath": {
27-
"type": "string"
31+
"description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
32+
"anyOf": [
33+
{
34+
"enum": ["auto"]
35+
},
36+
{
37+
"type": "string"
38+
},
39+
{
40+
"instanceof": "Function"
41+
}
42+
]
2843
},
2944
"serverSideRender": {
45+
"description": "Instructs the module to enable or disable the server-side rendering mode.",
3046
"type": "boolean"
3147
},
3248
"outputFileSystem": {
49+
"description": "Set the default file system which will be used by webpack as primary destination of generated files.",
3350
"type": "object"
3451
},
3552
"index": {
53+
"description": "Allows to serve an index of the directory.",
3654
"anyOf": [
3755
{
3856
"type": "boolean"
3957
},
4058
{
41-
"type": "string"
59+
"type": "string",
60+
"minlength": "1"
4261
}
4362
]
4463
}

test/__snapshots__/validation-options.test.js.snap

+22-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exports[`validation should throw an error on the "index" option with "{}" value
1010
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
1111
- options.index should be one of these:
1212
boolean | string
13+
-> Allows to serve an index of the directory.
1314
Details:
1415
* options.index should be a boolean.
1516
* options.index should be a string."
@@ -19,6 +20,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1
1920
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
2021
- options.index should be one of these:
2122
boolean | string
23+
-> Allows to serve an index of the directory.
2224
Details:
2325
* options.index should be a boolean.
2426
* options.index should be a string."
@@ -27,46 +29,59 @@ exports[`validation should throw an error on the "index" option with "0" value 1
2729
exports[`validation should throw an error on the "methods" option with "{}" value 1`] = `
2830
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
2931
- options.methods should be an array:
30-
[string, ...]"
32+
[string, ...]
33+
-> Allows to pass the list of HTTP request methods accepted by the middleware."
3134
`;
3235

3336
exports[`validation should throw an error on the "methods" option with "true" value 1`] = `
3437
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
3538
- options.methods should be an array:
36-
[string, ...]"
39+
[string, ...]
40+
-> Allows to pass the list of HTTP request methods accepted by the middleware."
3741
`;
3842

3943
exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = `
4044
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
4145
- options.mimeTypes should be an object:
42-
object {}"
46+
object {}
47+
-> Allows a user to register custom mime types or extension mappings."
4348
`;
4449

4550
exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = `
4651
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
4752
- options.outputFileSystem should be an object:
48-
object {}"
53+
object {}
54+
-> Set the default file system which will be used by webpack as primary destination of generated files."
4955
`;
5056

5157
exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = `
5258
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
53-
- options.publicPath should be a string."
59+
- options.publicPath should be one of these:
60+
\\"auto\\" | string | function
61+
-> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.
62+
Details:
63+
* options.publicPath should be \\"auto\\".
64+
* options.publicPath should be a string.
65+
* options.publicPath should be an instance of function."
5466
`;
5567

5668
exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = `
5769
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
58-
- options.serverSideRender should be a boolean."
70+
- options.serverSideRender should be a boolean.
71+
-> Instructs the module to enable or disable the server-side rendering mode."
5972
`;
6073

6174
exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = `
6275
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
63-
- options.serverSideRender should be a boolean."
76+
- options.serverSideRender should be a boolean.
77+
-> Instructs the module to enable or disable the server-side rendering mode."
6478
`;
6579

6680
exports[`validation should throw an error on the "writeToDisk" option with "{}" value 1`] = `
6781
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
6882
- options.writeToDisk should be one of these:
6983
boolean | function
84+
-> Allows to write generated files on disk.
7085
Details:
7186
* options.writeToDisk should be a boolean.
7287
* options.writeToDisk should be an instance of function."

test/validation-options.test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ describe('validation', () => {
2121
failure: [true],
2222
},
2323
publicPath: {
24-
success: ['/foo'],
24+
success: [
25+
'/foo',
26+
'',
27+
'auto',
28+
() => {
29+
return '/public/path';
30+
},
31+
],
2532
failure: [false],
2633
},
2734
serverSideRender: {

0 commit comments

Comments
 (0)