Skip to content

Support empty strings in enums #357

Closed
@ramnes

Description

@ramnes

Hey there, thanks for the nifty tool!

Something like

        access_tier:
          type: string
          enum:
            - ""
            - "Archive"
            - "Hot"
            - "Cool"

currently breaks openapi-python-client with

  File "openapi_python_client/parser/properties/__init__.py", line 545, in build_schemas
    schemas_or_err = update_schemas_with_data(name, data, schemas)
  File "openapi_python_client/parser/properties/__init__.py", line 521, in update_schemas_with_data
    prop, schemas = build_model_property(data=data, name=name, schemas=schemas, required=True, parent_name=None)
  File "openapi_python_client/parser/properties/__init__.py", line 261, in build_model_property
    prop, schemas = property_from_data(
  File "openapi_python_client/parser/properties/__init__.py", line 509, in property_from_data
    return _property_from_data(name=name, required=required, data=data, schemas=schemas, parent_name=parent_name)
  File "openapi_python_client/parser/properties/__init__.py", line 453, in _property_from_data
    return build_enum_property(
  File "openapi_python_client/parser/properties/__init__.py", line 343, in build_enum_property
    values = EnumProperty.values_from_list(enum)
  File "openapi_python_client/parser/properties/enum_property.py", line 62, in values_from_list
    if value[0].isalpha():
TypeError: 'NoneType' object is not subscriptable

While it doesn't seem like a very standard practice, I don't see anything in OpenAPI against it, and other code generators choose to support it (e.g. lukeautry/tsoa#468).

OpenAPI Spec File
https://github.com/drakkan/sftpgo/blob/main/httpd/schema/openapi.yaml

Desktop (please complete the following information):

  • OS: Linux
  • Python Version: 3.9
  • openapi-python-client version 0.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions