我具有根据jsonapi.org准则构造的HTTP请求有效负载:
{
"data": {
"type": "employee",
"attributes": {
"firstName": "John",
"lastName": "Doe",
}
}
}
然后我具有此有效负载的OpenApi规范(yaml):
employee:
type: object
required: [data]
properties:
data:
type: object
properties:
type:
type: string
enum: [employee]
attributes:
type: object
required: [firstName, lastName]
properties:
firstName:
type: string
example: 'John'
lastName:
type: string
example: 'Doe'
而且我想要根据规范验证有效负载(来自Ruby / Rails)。
存在openapi3_parser gem,但似乎只能验证规范,而不能验证实际有效载荷。
然后有jsonapi.org payload deserializers,但是那些似乎根本不关心OpenApi正式规范。
我使用OpenApi来描述有效负载,因为我通过Swagger免费获得了HTTP API文档。
有commitee宝石。验证器已紧密编织到机架中间件中,因此,如果要在机架堆栈之外使用验证器,则需要进行一些组装。