如何在Swagger中处理不需要的参数,以避免丢失位置参数错误?

时间:2019-04-23 12:17:31

标签: python-3.x swagger connexion

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

1 个答案:

答案 0 :(得分:1)

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

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

或添加默认参数

def read_surveydata(startDate, endDate, country, market='store'):