在尝试指示Dredd发出不同的请求以触发两个不同的场景时遇到了问题:代码201成功,代码400错误。
我尝试为每个HTTP状态代码设置一个单独的示例,但无法做到这一点。
我可以在example
中添加requestBody
部分,但随后将在两个示例中都使用它-成功和失败。
openapi: 3.0.2
info:
description: Body example per HTTP code illustration
version: 1.0.0
title: Profile
tags:
- name: profile
description: User profiles
paths:
/profiles:
post:
tags:
- profiles
summary: Create profile
operationId: createProfile
requestBody:
description: Create Profile
content:
application/json:
schema:
$ref: '#/components/schemas/CreateProfile'
required: true
responses:
'201':
description: Successful operation
headers:
Location:
schema:
type: string
description: Profile location
'400':
description: Profile is invalid (missing fields/null values)
content:
application/json:
schema:
$ref: '#/components/schemas/ProfileCreationError'
examples:
failing_scenrio:
summary: An example tailored to work with Dredd
value:
name: can't be blank
email: can't be blank
components:
schemas:
CreateProfile:
type: object
required:
- name
- email
- age
properties:
name:
type: string
email:
type: string
age:
type: integer
format: int32
minimum: 0
ProfileCreationError:
type: object
properties:
name:
type: string
email:
type: string
age:
type: integer
我希望能够同时对HTTP代码201和400进行测试。加分的示例说明了如何对path
参数执行相同的操作。例如,提供/profiles/{id}
(即200和404)的已发现和未发现示例。
答案 0 :(得分:0)
OpenAPI 3支持当前(2019年7月,Dredd v11.2.9)处于试验阶段,此特定行为仍未定义。该问题被跟踪为GitHub issue #1257。我建议您订阅该问题,以查看问题何时得到解决或考虑提供解决方案。