gpt4 book ai didi

openapi - 如何在 OpenAPI 3.0 中定义带有两个可选参数的路径?

转载 作者:行者123 更新时间:2023-12-04 10:34:39 27 4
gpt4 key购买 nike

我在 SwaggerHub 注册并使用 OpenAPI 3.0 创建了一个新 API。在我的 API 中,/tasks path 有 2 个非必需参数,但我无法将它们设置为不需要 - 编辑器显示“不允许的值”错误。

这是我的 API 定义:

openapi: 3.0.0
info:
description: A Simple IP Address API
title: VTasks
version: v1
servers:
# Added by API Auto Mocking Plugin
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/petrogromovo/Vtasks/1.0.0
- description: SwaggerHub API Auto Mocking
url: http://hosting.tk

paths:

/tasks:
get:
tags:
- tasks
summary: Get paginated / filtered tasks listing
operationId: tasks
parameters:
- name: page
in: path
description: The page number to be fetched. If missed default 1.
required: true
schema:
type: integer
- name: order_by
in: path
description: The order_by be fetched.
required: false // ERROR : should be equal to one of the allowed values allowedValues: true
schema:
type: string
- name: filter
in: path
description: The filter for title field.
required: false // ERROR : should be equal to one of the allowed values allowedValues: true
schema:
type: string
responses:
'200':
description: successful operation
'400':
description: Invalid tasks supplied
'404':
description: tasks were not found

但是如果我删除 required属性,我收到 2 个错误:

should have required property 'required'
missingProperty: required



什么是有效的语法?

最佳答案

这些参数应该是路径参数还是查询参数?

路径参数 ( in: path ) 是端点路径的一部分,因此必须由 {...} 指示在路径模板中:

paths:
/tasks/{page}/{order_by}/{filter}:

路径参数始终是必需的,即它们必须具有 required: true .

查询参数在查询字符串中发送,例如 /tasks?page=...&order_by=... .要使用查询参数,请将参数位置更改为 in: query .

更多信息: Describing Parameters

关于openapi - 如何在 OpenAPI 3.0 中定义带有两个可选参数的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60240725/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com