如何处理 Swagger 中的非必需参数以避免丢失位置参数错误?
How to handle non-required parameters in Swagger to avoid missing positional argument error?
我的端点有一个 Swagger 文件,其中一个端点有多个参数。你如何处理非必需参数?如果非必需参数具有空值,我对如何在我的 Python 文件中处理它提出了挑战。
这是我的 Swagger 定义:
/surveyData:
get:
operationId: "surveyData.read_surveydata"
summary: Gets the survey data for the client insights tracker.
parameters:
- in: query
name: startDate
type: string
required: true
description: The start date of the survey data.
- in: query
name: endDate
type: string
required: true
description: The end date of the survey data.
- in: query
name: country
type: string
description: The countries from which you would like to filter the survey data.
- in: query
name: market
type: string
这是我用 Python 编写的函数(使用 Connexion):
def read_surveydata(startDate, endDate, country, market):
您可以添加 "Default" 标签,例如:
parameters:
- name: filtros
in: "query"
required: false
description: Filter to query
type: "string"
default: "bndu"
或添加默认参数
def read_surveydata(startDate, endDate, country, market='store'):
我的端点有一个 Swagger 文件,其中一个端点有多个参数。你如何处理非必需参数?如果非必需参数具有空值,我对如何在我的 Python 文件中处理它提出了挑战。
这是我的 Swagger 定义:
/surveyData:
get:
operationId: "surveyData.read_surveydata"
summary: Gets the survey data for the client insights tracker.
parameters:
- in: query
name: startDate
type: string
required: true
description: The start date of the survey data.
- in: query
name: endDate
type: string
required: true
description: The end date of the survey data.
- in: query
name: country
type: string
description: The countries from which you would like to filter the survey data.
- in: query
name: market
type: string
这是我用 Python 编写的函数(使用 Connexion):
def read_surveydata(startDate, endDate, country, market):
您可以添加 "Default" 标签,例如:
parameters:
- name: filtros
in: "query"
required: false
description: Filter to query
type: "string"
default: "bndu"
或添加默认参数
def read_surveydata(startDate, endDate, country, market='store'):