我有根据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文档。