这是我的yaml(setup.yml):
openapi: 3.0.2
info:
title: "My Setup"
description: "Some old nonsense"
version: 1.0.0
contact:
name: "Tom Riddle"
email: "tom@not-a-muggle.co.uk"
url: "https://deatheaters-anonymous.org"
termsOfService: MIT
servers: []
paths: {}
components:
schemas:
CodeValue:
type: integer
minimum: 200
maximum: 302
AgeGroup:
type: string
enum: [baby, child, teen, adult, old]
Age:
anyOf:
- type: string
enum: [baby, child, teen, adult, old]
- type: integer
运行openapi生成器(从https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1->;openapi-generator-cli-4.3.1.jar下载)并使用java -jar openapi-generator-cli.jar generate -g python -i setup.yml -o src
运行cli,我得到以下结果:
src/openapi_client/models
包含age.py
和age_group.py
。。。但是没有{age_group.py
看起来不错。枚举在那里,我可以看到值,等等。太好了李>age.py
甚至与yaml定义不相似(见下文)。没有检查值是整数还是字符串(即anyOf
没有正确实现),也没有提及枚举的痕迹。事实上,在生成的项目结构中找不到它---&燃气轮机<为什么强># coding: utf-8
"""
My Setup
Some old nonsense # noqa: E501
The version of the OpenAPI document: 1.0.0
Contact: tom@not-a-muggle.co.uk
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
from openapi_client.configuration import Configuration
class Age(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
}
attribute_map = {
}
def __init__(self, local_vars_configuration=None): # noqa: E501
"""Age - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
self.discriminator = None
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, Age):
return False
return self.to_dict() == other.to_dict()
def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, Age):
return True
return self.to_dict() != other.to_dict()
目前没有回答
相关问题 更多 >
编程相关推荐