java – 如何覆盖RAML 1.0中的对象数组属性类型

前端之家收集整理的这篇文章主要介绍了java – 如何覆盖RAML 1.0中的对象数组属性类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个通用的 Java类型,如下所示:
  1. class Response<D> {
  2. List<D> data;
  3. }

并希望创建类似于RAML 1.0(我是新手)的东西.

我的第一个办法是

  1. types:
  2. Response:
  3. type: object
  4. properties:
  5. data: object[]

使用它时

  1. body:
  2. type: Response
  3. properties:
  4. data: MyDataType[]

从API-Workbench我总是得到一个“从响应继承的属性数据的非法覆盖”.

另一个想法是使用重复:

  1. types:
  2. Response:
  3. type: object
  4. properties:
  5. data: object
  6. repeat: true

并分别

  1. body:
  2. type: Response
  3. properties:
  4. data: MyDataType
  5. repeat: true

现在非法覆盖已经消失了,但在API控制台中,我现在得到一个“未捕获的TypeError”.

怎么解决?还是需要一个完全不同的方法?任何想法?

@H_502_29@解决方法
据了解,Response是抽象不同类型的数据,但格式相似.一种方法是使用resourcesTypes抽象出响应中的相似性,并在类型中定义具体的数据.
  1. #%RAML 1.0
  2. title: New API
  3. version: v1
  4. baseUri: http://api.samplehost.com
  5. mediaType: application/json
  6.  
  7. types:
  8. User:
  9. usage: A user in the system
  10. properties:
  11. firstname:
  12. required: true
  13. lastname:
  14. required: true
  15.  
  16. ArticleId:
  17. usage: An id of any article in the system
  18. type: number
  19.  
  20. Article:
  21. usage: Pattern for any article in the system
  22. properties:
  23. id:
  24. type: ArticleId
  25. required: true
  26. created:
  27. type: date
  28. required: true
  29.  
  30. #######################################
  31. # the following captures the similarity:
  32. #######################################
  33.  
  34. resourceTypes:
  35. collection:
  36. get:
  37. responses:
  38. 200:
  39. body:
  40. properties:
  41. data: <<typename>>[]
  42.  
  43.  
  44. ###############
  45. # API:
  46. ###############
  47.  
  48. /user:
  49. description: All the users
  50. type:
  51. collection:
  52. typename: User
  53.  
  54. /article:
  55. description: All the articles
  56. type:
  57. collection:
  58. typename: Article

猜你在找的Java相关文章