使用OpenAPI 3.0是一种将布尔查询参数链接到特定示例的方法



我在swagger.com中模拟了这一点,所以我正在使用的前端家伙有一个模拟的api,他们可以在我构建端点时发送查询。

是否有可能通过改变参数来过滤给定端点上的示例,如果可以,如何做到这一点?

更具体地说,当all_system_vans = false or null

时,我想返回#components/examples/default_vans

all_system_vans = true

时返回#components/examples/all_system_vans-is-true

下面是我的openapi架构。

openapi: 3.0.0
info:
title: "Van life"
description: "VANS"
version: "1.0.0"
tags:
- name: "van"
description: "All things Van (life)."
paths:
/vans:
get:
tags:
- "van"
summary: ""
operationId: "getVan"
parameters:
- in: "query"
name: "all_system_vans"
description: "Default of false will get vans in ready to go, true will get all system vans." 
required: false
schema: 
type: "boolean"
default: false
responses:
"200":
description: "Ok"
content:
application/json:
schema:
$ref: "#/components/schemas/Vans"
examples:
buffer_only_vans:
$ref: "#/components/examples/default_vans"
all_system_vans:
$ref: "#/components/examples/all_system_vans-is-true"
"400":
$ref: "#/components/responses/400"
"404":
$ref: "#/components/responses/404"
components:
responses: 
"400":
description: "Invalid status value"
"404":
description: "Whatever you were looking for is not found."
examples:
default_vans:
summary: ""
value: {"vans": ["van_2", "van_3", "van_5", "van_7", "van_11"]}
all_system_vans-is-true:
summary: ""
value: {"vans": ["van_1", "van_2", "van_3", "van_4", "van_5", "van_6", "van_7", "van_9", "van_10", "van_11"]}

schemas:
Vans:
type: "object"
properties: 
vans: 
type: "array"
items: 
type: "string"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"

OpenAPI规范没有任何语法来将响应定义与特定的输入值关联起来。下面是OpenAPI规范存储库中的一个相关特性请求:
请求/响应相关性

但是一些OpenAPI模拟/服务虚拟化工具支持这种请求/响应关联。例如,ReadyAPI Virtualization(由我工作的公司制作)具有各种响应调度选项,包括顺序和随机响应选择以及基于请求数据选择响应。

相关内容

  • 没有找到相关文章

最新更新