【问题标题】:Abstract class or interface in RAML modelingRAML 建模中的抽象类或接口
【发布时间】:2019-04-11 01:58:23
【问题描述】:

是否可以使用 RAML 对抽象类或接口进行建模?如果不是,我们如何在子类型必须定义的超类型中施加约束?

【问题讨论】:

    标签: rest api api-design raml


    【解决方案1】:

    您可以对超类型和继承建模,如下所示:

    types:
      ResponseNoId:
        properties:
          something1: 
          something2?:
      ResponseId:
        type: ResponseNoId
        properties:
          id:
      Response:
        ResponseNoId|ResponseId
    
    /test:
      get:
        responses:
          200:
            body:
              application/json:
                type: ResponseId
    

    在此示例中,ResponseId 从ResponseNoId 继承something1 和something2,但添加了一个名为id 的新属性。

    Response 还允许您在资源中使用其中任何一个。 在您的资源中,您现在可以定义 type: Response 并且它只允许其中一种子类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2011-01-09
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 2011-04-13
      相关资源
      最近更新 更多