RAML建模中的抽象类或接口

问题描述 投票:0回答:1

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

rest api api-design raml
1个回答
0
投票

您可以在类型中建模超类型和继承:

types:
  ResponseNoId:
    properties:
      something1: 
      something2?:
  ResponseId:
    type: ResponseNoId
    properties:
      id:
  Response:
    ResponseNoId|ResponseId

/test:
  get:
    responses:
      200:
        body:
          application/json:
            type: ResponseId

在这个例子中,ResponseIdsomething1继承了something2ResponseNoId但添加了一个名为id的新属性。

此外,Response允许您在资源中使用。在您的资源中,您现在可以定义type: Response,它只允许其中一种子类型。

© www.soinside.com 2019 - 2024. All rights reserved.