我在尝试指示 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
param 执行相同操作的示例的奖励点。例如,为/profiles/{id}
(即 200 和 404)提供已找到和未找到的示例。