You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated README.md with relevant information about the sharedSchemaId (#280)
* Updated README.md with relevant information about the sharedSchemaId. #276
* Improve docs: added more details on field conversion [#277]
* Fixed typo
* Added an example for the non-file field validation
* Apply suggestions from code review
Minor styling changes on the text.
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
* Minor wording update
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
If provided, the `sharedSchemaId` parameter must be a string ID and a shared schema will be added to your fastify instance so you will be able to apply the validation to your service (like in the example mentioned above).
298
+
299
+
The shared schema, that is added, will look like this:
300
+
```js
301
+
{
302
+
type:'object',
303
+
properties: {
304
+
encoding: { type:'string' },
305
+
filename: { type:'string' },
306
+
limit: { type:'boolean' },
307
+
mimetype: { type:'string' }
308
+
}
309
+
}
310
+
```
311
+
312
+
### JSON Schema non-file field
313
+
When sending fields with the body (`attachFieldsToBody` set to true), the field might look like this in the `request.body`:
314
+
```json
315
+
{
316
+
"hello": "world"
317
+
}
318
+
```
319
+
The mentioned field will be converted, by this plugin, to a more complex field. The converted field will look something like this:
320
+
```js
321
+
{
322
+
hello: {
323
+
fieldname:"hello",
324
+
value:"world",
325
+
fieldnameTruncated:false,
326
+
valueTruncated:false,
327
+
fields: body
328
+
}
329
+
}
330
+
```
331
+
332
+
It is important to know that this conversion happens BEFORE the field is validated, so keep that in mind when writing the JSON schema for validation for fields that don't use the shared schema. The schema for validation for the field mentioned above should look like this:
333
+
```js
334
+
hello: {
335
+
properties: {
336
+
value: {
337
+
type:'string'
338
+
}
339
+
}
340
+
}
341
+
```
342
+
296
343
## Access all errors
297
344
298
345
We export all custom errors via a server decorator `fastify.multipartErrors`. This is useful if you want to react to specific errors. They are derived from [fastify-error](https://github.com/fastify/fastify-error) and include the correct `statusCode` property.
0 commit comments