模拟响应

正如其名所示,mock-response 策略用于模拟 API 和操作。 它会取消正常的管道执行,并将模拟的响应返回给调用方。 该策略始终尝试返回保真度最高的响应。 它首选响应内容示例(若可用)。 如果提供架构而不提供示例,它将根据架构生成示例响应。 如果既找不到示例又找不到架构,则返回无内容的响应。

注意

按照策略声明中提供的顺序设置策略的元素和子元素。 详细了解如何设置或编辑 API 管理策略

策略语句

<mock-response status-code="code" content-type="media type"/>

属性

属性 说明 需要 默认
status-code 指定响应状态代码,并用于选择相应的示例或架构。 不允许使用策略表达式。 200
content-type 指定 Content-Type 响应标头值,并用于选择相应的示例或架构。 不允许使用策略表达式。

使用情况

使用注意事项

示例

<!-- Returns 200 OK status code. Content is based on an example or schema, if provided for this status code. First found content type is used. If no example or schema is found, the content is empty. -->
<mock-response/>

<!-- Returns 200 OK status code. Content is based on an example or schema, if provided for this status code and media type. If no example or schema found, the content is empty. -->
<mock-response status-code='200' content-type='application/json'/>

后续步骤

有关使用策略的详细信息,请参阅: