加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 05:25:36 所属栏目:Java 来源:网络整理
导读:我有一个通用的 Java类型,如下所示: class ResponseD { ListD data;} 并希望创建类似于RAML 1.0(我是新手)的东西. 我的第一个办法是 types: Response: type: object properties: data: object[] 使用它时 body: type: Response properties: data: MyDataTyp
我有一个通用的 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读