我想在我的 api 文档中用 2 位表示小数,用 1 位表示小数。我正在使用 swagger 2.0,规范中是否有内置定义类型或任何其他“圆形”参数,或者我唯一的选择是使用“x-”扩展名?
问问题
19343 次
1 回答
20
OpenAPI (fka Swagger) 规范使用JSON Schema的子集来描述数据类型。
如果参数作为数字传递,您可以尝试按照此 Q&AmultipleOf
中的建议使用:
type: number
multipleOf: 0.1 # up to 1 decimal place, e.g. 4.2
# multipleOf: 0.01 # up to 2 decimal places, e.g. 4.25
然而,由于浮点数学特性multipleOf
,对浮点数的验证可能不可靠。
如果您的号码作为字符串传递,您可以pattern
为所需的号码格式指定正则表达式:
type: string
pattern: your_regex
无论如何,您也可以在description
.
于 2017-07-07T11:08:38.127 回答