0

我的端点有一个 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):
4

1 回答 1

1

您可以添加“默认”标签,例如:

      parameters:
        - name: filtros
          in: "query"
          required: false
          description: Filter to query
          type: "string"
          default: "bndu"

或者添加一个默认参数

def read_surveydata(startDate, endDate, country, market='store'):
于 2019-04-23T12:41:51.533 回答