python的open-api生成器不适用于子类型或anyOf / allOf

问题描述

这是我的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,old]
        - type: integer

运行openapi-generator(从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)获得以下结果:

  1. src/openapi_client/models包含age.pyage_group.py ...但没有code_value.py ---> 为什么?
  2. 文件age_group.py看起来不错。枚举在那里,我可以看到 etc。很棒的值。
  3. 文件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()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...