RAML - 查询参数中的字符串类型接受空值

问题描述

我为 API 创建了一个查询参数,其中一个参数如下所示,

Testing:
  description:
  required: true
  type: string
  example: “ABCDEFG”

在模拟测试期间,我可以看到此查询参数接受了空值。当 Type 为 String 时,您能否确认 null 是否是可接受的值?如果它是可以接受的,有没有办法只接受字符,而不接受空引号和空引号??谢谢。

注意:- 我尝试了所有这些值 Null,null 和 nil 。所有值都被接受,它不会抛出错误

添加示例:-

API 网址:- http://localhost:8081/api/patient?patientLongitude=10&patientLatitude=20&Testing=Abcd 响应:- 成功(正确)

API 网址:- http://localhost:8081/api/patient?patientLongitude=10&patientLatitude=20&Testing="" 响应:- 成功(自测试 QueryParam 后预期失败响应 是空引号)

API 网址:- http://localhost:8081/api/patient?patientLongitude=10&patientLatitude=20&Testing=null 响应:- 成功(自测试 QueryParam 后预期失败响应 为空)

API 网址:- http://localhost:8081/api/patient?patientLongitude=10&patientLatitude=20&Testing= 响应:- 成功(自测试 QueryParam 后预期失败响应 没有任何价值) - 我可以通过在 RAML 中添加最小长度为 1 来解决这个问题

解决方法

也许您需要将查询参数定义为可为空:

type: string | nil