我有一个响应200 OK并返回HTML的API调用。我想将其添加到我的API文档 (特别是因为我使用dredd进行了验证,除非我提供它与期望的响应正文测试失败)。如何 我会在Swagger中做到这一点?如何在Swagger中为内容类型:text/html的Response Body提供示例值
---更多细节--- 我通过API调用的响应是200 OK,并有一行响应体:
<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>
我可以很容易地在定义响应主体的蓝图以下形式:
+ Response 302 (text/html; charset=utf-8)
+ Body
`<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>`
但我不知道如何在Swagger中做到这一点。几乎所有我能找到的例子都是针对应用程序/ json响应的(可以理解),并且我在为这种响应猜测正确的语法时遇到了问题 。
我的文档中的相关招摇的文字是这样的(至今无指定响应主体,因此与空体的Dredd 失败,因为响应主体应该是<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>
):
# this is my API spec in YAML
swagger: '2.0'
info:
title: My API (Swagger)
description: blablabla
version: "1.0.0"
# the domain of the service
host: my.domain.com
# array of all schemes that your API supports
schemes:
- https
# will be prefixed to all paths
basePath:/
produces:
- application/json; charset=utf-8
paths:
/users/password:
post:
summary: Password Reset
description: |
Handles Reset password for existing user.
consumes:
- application/x-www-form-urlencoded
produces:
- text/html; charset=utf-8
parameters:
- name: "user[email]"
description: email
in: formData
required: true
type: string
default: "[email protected]"
tags:
- Reset Password
responses:
200:
description: Success
请您发表评论对此有任何建议。谢谢!