Fastify 系列教程:

验证

Fastify 可以验证请求信息,只有符合验证规则的请求才会被处理。

JSON Schema

什么是 JSON Schema ,通俗来讲,JSON Schema 就是“描述 JSON 数据格式的一段 JSON”。

首先,JSON Schema 也是一个 JSON 字符串,下面来看一个简单的 JSON Schema:

{     "$schema": "http://json-schema.org/draft-04/schema#",     "title": "Product",     "description": "A product from Acme's catalog",     "type": "object",     "properties": {         "id": {             "description": "The unique identifier for a product",             "type": "integer"         },         "name": {             "description": "Name of the product",             "type": "string"         },         "price": {             "type": "number",             "minimum": 0,             "exclusiveMinimum": true         }     },     "required": ["id", "name", "price"] }

上面这段规则描述了这样一个JSON:

1、type 表示该 JSON 的类型是一个 "object"。

type 的参数可以是:number