是否可以使用RAML对抽象类或接口进行建模?如果没有,我们如何在子类型必须定义的超类型中强加约束?
您可以在类型中建模超类型和继承:
types:
ResponseNoId:
properties:
something1:
something2?:
ResponseId:
type: ResponseNoId
properties:
id:
Response:
ResponseNoId|ResponseId
/test:
get:
responses:
200:
body:
application/json:
type: ResponseId
在这个例子中,ResponseId
从something1
继承了something2
和ResponseNoId
但添加了一个名为id
的新属性。
此外,Response
允许您在资源中使用。在您的资源中,您现在可以定义type: Response
,它只允许其中一种子类型。