在我的REST应用程序模型中,我的许多实体都包含一个"Auditable“接口。这迫使我将这些子路径添加到这些实体端点:
/myEntityResource:
#... boring code ...
/createdBy:
get:
responses:
200:
body:
application/hal+json:
example: !include samples/userAccount.json
/lastModifiedBy:
get:
responses:
200:
body:
application/hal+json:
example: !include samples/userAccount.json
理想的解决方案应该是向端点添加一个“可审计”的特征,但是根据RAML的定义,特征只适用于动词级别。
对我来说,另一个理想的选择应该是定义一个包含两个路径的资源类型"auditableItem“,但是RAML定义不允许向资源类型添加路径。
我目前最好的方法是将两个路径都添加到每个端点,并将主体包含在一个单独的文件中:
/createdBy: !include auditableBody.raml
/lastModifiedBy: !include auditableBody.raml
有没有更好的办法?
发布于 2016-01-05 10:04:24
简短的回答是“是”。
根据http://apiworkbench.com/docs/#creating-resource-type的说法,您可以将其重构为:
#%RAML 1.0
title: Auditable Example
version: 1
resourceTypes:
Auditable-createdBy:
get:
responses:
200:
body:
application/hal+json:
# example: !include samples/userAccount.json
Auditable-lastModifiedBy:
get:
responses:
200:
body:
application/hal+json:
# example: !include samples/userAccount.json
/myEntityResource:
/createdBy:
type: Auditable-createdBy
/lastModifiedBy:
type: Auditable-lastModifiedBy
当然,您也可以将resourceTypes
移动到一个独立的文件中。
https://stackoverflow.com/questions/31606004
复制