一个人如何表明在招摇的文档中禁止使用数字? [英] How does one indicate that a number is prohibited for use in swagger documentation?

查看:84
本文介绍了一个人如何表明在招摇的文档中禁止使用数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的招摇文档中指定一个名为myNumber的属性,该属性可以是[-1,10]中的任何整数,但0除外.这是我到目前为止所拥有的:

I am trying to specify a property in my swagger documentation called myNumber, which can be any integer in [-1, 10] except 0. This is what I have so far:

myNumber:
    type: integer
    description: You can use any number in [-1, 10] except 0.
    minimum: -1
    maximum: 10

如何明确禁止使用0?我尚未在openAPI文档中找到任何规范.这有可能吗?

How can I be explicit that 0 is prohibited? I haven't found any specification for this in the openAPI docs. Is this even possible?

推荐答案

选项1:枚举

如果可能值的列表很小,则可以将它们全部列在enum中:

myNumber:
  type: integer
  description: You can use any number in [-1, 10] except 0.
  enum: [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

这是最简单的解决方案,可在OpenAPI 2.0和3.0中使用.

This is the easiest solution and works in both OpenAPI 2.0 and 3.0.

在OpenAPI 3.0中,您可以使用oneOf定义两个可能的值范围:

In OpenAPI 3.0 you can use oneOf to define two ranges of possible values:

myNumber:
  type: integer
  description: You can use any number in [-1, 10] except 0.
  oneOf:
    - enum: [-1]  # shorthand for `minimum: -1` + `maximum: -1`
    - minimum: 1
      maximum: 10

选项3:不是

OpenAPI 3.0还支持not来定义实例不能满足的条件.例如,您按如下所示排除值0:

Option 3: not

OpenAPI 3.0 also supports not to define conditions that an instance must not meet. For example, you exclude the value 0 as follows:

myNumber:
  type: integer
  description: You can use any number in [-1, 10] except 0.
  minimum: -1
  maximum: 10
  not:
    enum: [0]

但是,对not的实际工具支持可能有所不同.

However, actual tooling support for not may vary.

这篇关于一个人如何表明在招摇的文档中禁止使用数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆