OpenAPI 规范 - 如何指定接受一定范围值的输入参数

Har*_*gde 5 specifications openapi

使用 OpenAPI 3.0.3,我定义了一个接受两个输入查询参数的 API 规范。

- name: land_area_llimit
  in: query
  description: Lower limit for land area comparison
  required: false
  schema:
      type: integer
- name: land_area_ulimit
  in: query
  description: Upper limit for land area comparison
  required: false
  schema:
      type: integer
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想将两者结合起来,并且只有一个参数,该参数接受一个范围,例如: [a,b] where a > 0 and b > a > 0。比如说:

- name: land_area
  in: query
  description: lower and upper bounds for land area comparison
  required: false
  schema:
      type: range     
  ## With some way to specify that this parameter accepts a lower bound and an upper bound. 

Run Code Online (Sandbox Code Playgroud)

我知道minimummaximum。这将预设范围。我正在寻找作为输入提供的范围。这能实现吗?

Hel*_*len 1

您可以将范围定义为元组(自 OpenAPI 3.1 起支持)或包含 2 个元素的数组。

但是,无法拥有minimum基于另一个值的动态属性。您需要在描述中提及此要求并验证后端的值。

# openapi: 3.1.0

- name: land_area
  in: query
  description: Lower and upper bounds for land area comparison
  required: false
  schema:
    type: array
    prefixItems:
    - type: integer
      description: Lower bound for land area comparison
    - type: integer
      description: >-
        Upper bound for land area comparison.
        Must be greater than the lower bound.
    minItems: 2
    additionalItems: false
Run Code Online (Sandbox Code Playgroud)