raml模板_RAML:定义示例的四种方法

本文重点介绍了四种指定期望的传入和传出主体的方法,包括内联作为正文示例、包含多个YAML/JSON示例、包含一个NamedExample RAML、提供示例作为简单文本消息,还给出完整代码段,同时提到RESTful API设计的五项原则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

raml模板

raml模板

为RESTful API端点定义示例主体有效负载和响应是设计现代API的重要方面。 这些示例确保了API合约期望从客户端接收并响应客户端的内容。

在本文中,我将通过示例重点介绍四种指​​定期望的传入和传出主体的方法。

内联作为正文示例

在根RAML中使用关键字example (单数)显式地包含示例,后跟example的JSON或YAML表示形式。 请参见以下示例中的第10行。

包括多个YAML / JSON示例

使用!include关键字引用包含示例的文件。 您必须使用examples (多个)并为示例唯一命名。 在这种情况下,示例被命名为ex1ex2 。 请参见下面的示例中的第16/17行。

包括一个NamedExample RAML

引用一个NamedExample RAML文件,该文件以RAML格式定义了示例。 您必须使用examples (复数)关键字,并且可以提供一个或多个示例。 请参见下面示例中的第22行。

提供示例作为简单文本消息

使用example (单数)关键字后跟一条文本消息。 请参见下面示例中的第29行。

完整代码段

下面的RAML代码片段显示了将示例添加到上面讨论的规范中的四种方法。

RESTful API设计的五项原则

在编写API规范之前,必须考虑RESTful API规范的五个主要方面。 通过RESTful API设计了解更多信息。

翻译自: https://www.javacodegeeks.com/2020/10/raml-four-ways-to-define-examples.html

raml模板

如下RAML格式API定义文件提示如下错误,请分析并给出解决方案: #%RAML 1.0 title: Standard Graph API - QA version: v1 annotationTypes: components: any oas-summary: type: string allowedTargets: Method oas-tags: type: 'string[]' allowedTargets: Method (components): {} types: Emphasis: description: 高亮状态的图形样式 type: object properties: color: description: 线的颜色 type: string | nil fontSize: description: 字体大小 type: number format: float width: description: 线的宽度 type: integer format: int32 additionalProperties: false GraphData: type: object properties: links: description: 关系图的节点间的关系数据集合 type: array | nil items: type: GraphLink nodes: description: 关系图的节点数据集合 type: array | nil items: type: GraphNode additionalProperties: false GraphLink: description: 关系图的节点间的关系数据实体类 type: object properties: label: type: Label lineStyle: type: LineStyle source: description: 边的源节点名称的字符串,也支持使用数字表示源节点的索引 type: string | nil target: description: 边的目标节点名称的字符串,也支持使用数字表示源节点的索引 type: string | nil tooltip: type: Label additionalProperties: false GraphNode: description: 关系图的节点数据实体类 type: object properties: itemStyle: type: ItemStyle label: type: ItemStyle name: description: 节点名称 type: string | nil symbolSize: description: '该节点标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10' type: integer format: int32 value: description: 节点值 type: string | nil x: description: 节点的初始 x 坐标值。在不指定的时候需要指明layout属性选择布局方式 type: integer format: int32 'y': description: 节点的初始 y 坐标值。在不指定的时候需要指明layout属性选择布局方式 type: integer format: int32 additionalProperties: false ItemStyle: description: 元素样式实体类 type: object properties: color: description: 颜色 type: string | nil additionalProperties: false Label: description: 标签和提示框配置项实体类 type: object properties: color: description: 文字的颜色 type: string | nil emphasis: type: Emphasis formatter: description: 标签内容格式器,支持字符串模板和回调函数两种形式,字符串模板与回调函数返回的字符串均支持用 \n 换行 type: string | nil show: description: 是否显示标签 type: boolean additionalProperties: false LineStyle: description: 关系边的线条样式实体类 type: object properties: color: description: 线的颜色 type: string | nil curveness: description: 边的曲度,支持从 0 到 1 的值,值越大曲度越大 type: number format: float emphasis: type: Emphasis type: description: 线的类型,可选'solid'、'dashed'、'dotted' type: string | nil additionalProperties: false /api/Graph: get: responses: '200': description: OK body: text/plain: type: GraphData application/json: type: GraphData text/json: type: GraphData (oas-summary): 获取关系图的所有节点和节点间的关系数据 (oas-tags): - Graph /AppNames: get: responses: '200': description: OK body: text/plain: type: array items: type: string application/json: type: array items: type: string text/json: type: array items: type: string (oas-tags): - Graph '/{appName}': get: responses: '200': description: OK (oas-tags): - Graph uriParameters: appName: type: string 错误如下:· Invalid API descriptor -- errors found: 4 AMF: Property 'items' not supported in a RAML 1.0 union node Location: file:///C:/Users/leoqian/Downloads/swagger.raml Position: Line 36, Column 8 AMF: Property 'items' not supported in a RAML 1.0 union node Location: file:///C:/Users/leoqian/Downloads/swagger.raml Position: Line 41, Column 8 RAML: Invalid element items: org.raml.v2.internal.impl.commons.nodes.TypeDeclarationNode@125fdd74. -- C:/Users/leoqian/Downloads/swagger.raml [line=36, col=9] RAML: Invalid element items: org.raml.v2.internal.impl.commons.nodes.TypeDeclarationNode@1951676e. -- C:/Users/leoqian/Downloads/swagger.raml [line=41, col=9]
最新发布
07-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值