我有类似的openapi.yml规范文件:
openapi: 3.0.1
info:
title: some title
version: "4"
paths:
/users/{userId}/data:
get:
summary: some summary
description: some description
operationId: userData
parameters:
- name: some-token
in: header
description: desc
required: true
schema:
type: string
example: "tokenExample"
...
- name: userId
in: path
description: desc
required: true
schema:
type: string
example: "someID"
responses:
"200":
description: desc
content:
"application/json":
schema:
$ref: '#/components/schemas/DataModel'
components:
schemas:
DataModel:
type: object
properties:
data1:
type: integer
format: int32
data2:
type: integer
format: int32
data3:
type: integer
format: int32测试执行给我这样的结果:
request:
method: GET
uri: /users/<someID>/data
headers:
some-token: 389fe056-e904-48fd-8d89-caaf8769ab84
...
User-Agent: Dredd/14.0.0 (Linux 5.10.104-linuxkit; x64)
body:
expected:
headers:
Content-Type: application/json; charset=utf-8
body:
{
"data1": 0,
"data2": 0,
"data3": 0
}
statusCode: 200
actual:
statusCode: 200
headers:
server: Apache-Coyote/1.1
set-cookie: rememberMe=deleteMe; Path=/somepath; Max-Age=0; Expires=Thu, 17-Nov-2022 08:41:46 GMT; Secure
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
date: Fri, 18 Nov 2022 08:41:46 GMT
connection: close
bodyEncoding: utf-8
body:
{
"data1": 0,
"data2": 0,
"data3": 0
}主体代码和状态代码完全匹配,但是有些东西,可能是头代码,无法验证。如何通过这个测试的验证?通过测试所必需的标头匹配吗?如果是,如何实现标头匹配?
PS。我现在已经非常similar question了,但是它很久以前就被问到了,所以我决定刷新它和更多的细节。
发布于 2022-11-18 13:58:33
运行具有调试日志级别的dredd (--logLevel= debug )有助于我识别问题。在内容响应中,这需要完全是"application/json;charset=utf-8",而不是"application/json"。
https://stackoverflow.com/questions/74487193
复制相似问题