我有一个通用的
Java类型,如下所示:
class Response<D> { List<D> data; }
并希望创建类似于RAML 1.0(我是新手)的东西.
我的第一个办法是
types: Response: type: object properties: data: object[]
使用它时
body: type: Response properties: data: MyDataType[]
从API-Workbench我总是得到一个“从响应继承的属性数据的非法覆盖”.
另一个想法是使用重复:
types: Response: type: object properties: data: object repeat: true
并分别
body: type: Response properties: data: MyDataType repeat: true
现在非法覆盖已经消失了,但在API控制台中,我现在得到一个“未捕获的TypeError”.
解决方法
据了解,Response是抽象不同类型的数据,但格式相似.一种方法是使用resourcesTypes抽象出响应中的相似性,并在类型中定义具体的数据.
#%RAML 1.0 title: New API version: v1 baseUri: http://api.samplehost.com mediaType: application/json types: User: usage: A user in the system properties: firstname: required: true lastname: required: true ArticleId: usage: An id of any article in the system type: number Article: usage: Pattern for any article in the system properties: id: type: ArticleId required: true created: type: date required: true ####################################### # the following captures the similarity: ####################################### resourceTypes: collection: get: responses: 200: body: properties: data: <<typename>>[] ############### # API: ############### /user: description: All the users type: collection: typename: User /article: description: All the articles type: collection: typename: Article