如何解决python 客户端问题和使用鉴别器对象打开 api 规范
我有以下基本的开放 API 规范。它主要基于开放 API 规范文档中显示的通过判别器的层次结构示例。
openapi: 3.0.0
info:
title: Test Inheritance
version: 1.0.0
servers:
- url: /
paths:
/test:
get:
operationId: test
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Dog"
required: true
responses:
"200":
description: Success
default:
description: Unexpected Error
components:
schemas:
Pet:
type: object
required:
- petType
properties:
petType:
type: string
discriminator:
propertyName: petType
mapping:
dog: Dog
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
name:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: string
Lizard:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
lovesRocks:
type: boolean
然后我使用 openapi-generator-cli-5.0.1.jar
生成器生成了一个 python 客户端。
以下简单代码:
dog = Dog(name='Nora',pet_type='dog')
configuration = Configuration(host=f"http://localhost")
api_client = ApiClient(configuration=configuration)
self.api_instance = DefaultApi(api_client)
self.api_instance.test(dog=dog)
出现错误
File "test/openapi_client/api_client.py",line 771,in __call__
return self.callable(self,*args,**kwargs)
File "test/openapi_client/api/default_api.py",line 102,in __test
return self.call_with_http_info(**kwargs)
File "test/openapi_client/api_client.py",line 818,in call_with_http_info
self.__validate_inputs(kwargs)
File "test/openapi_client/api_client.py",line 712,in __validate_inputs
fixed_val = validate_and_convert_types(
File "test/openapi_client/model_utils.py",line 1386,in validate_and_convert_types
results = get_required_type_classes(required_types_mixed,spec_property_naming)
File "test/openapi_client/model_utils.py",line 1017,in get_required_type_classes
valid_classes.extend(get_possible_classes(required_type,spec_property_naming))
File "test/openapi_client/model_utils.py",line 977,in get_possible_classes
possible_classes.extend(get_discriminated_classes(cls))
File "test/openapi_client/model_utils.py",line 964,in get_discriminated_classes
possible_classes.extend(get_discriminated_classes(discr_cls))
File "test/openapi_client/model_utils.py",in get_discriminated_classes
possible_classes.extend(get_discriminated_classes(discr_cls))
[Previous line repeated 970 more times]
File "test/openapi_client/model_utils.py",line 960,in get_discriminated_classes
if is_type_nullable(cls):
File "test/openapi_client/model_utils.py",line 1319,in is_type_nullable
for t in input_type._composed_schemas.get('oneOf',()):
File "test/openapi_client/model_utils.py",line 42,in __get__
if self.result_key in vars(self):
RecursionError: maximum recursion depth exceeded while calling a Python object
我做错了什么?我定义开放规范的方式有问题,或者我正在使用客户端,还是开放 api 生成器有问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。