0

我使用 swagger-codegen 从我们的 Spring Boot 应用程序创建了一个 python 客户端。

除了调用具有可选参数的 API(必需 = False)时,所有 API 都运行良好。

  • 在使用可选参数调用 API 时,当我们不向 api 参数传递任何值时,它默认为 None。
 def get_http_info(self, **kwargs): 
      # This is the optional query parameter
      all_params = ['region_id'] 

      # It gets set here if present in the API call, otherwise it is None by default.
      query_params = []
      if 'region_id' in params:
         query_params.append(('regionId', params['region_id']))  # noqa: E501

  • 然后将其作为“None”值传递给后端服务器,后端服务器实际上需要一个空值(如果未设置可选参数)。
 @Override
 public ResponseEntity<List<Info>> getInfo(@Valid String regionId) {
     // When regionId is left blank in the python API call, it is coming to the backend as "None"
 }
  • 因此,后端服务器返回错误的状态码。

我遇到了这两个 swagger-codegen 问题(看起来它们仍然开放),它们似乎相关:

有没有办法确保在通过 swagger-codegen 创建 python 客户端时,如果 API 调用中没有提供可选的查询参数,我们会生成一个不传入可选查询参数的构造函数?

4

0 回答 0