Skip to content

Support empty strings in enums #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ramnes opened this issue Mar 23, 2021 · 1 comment · Fixed by #358
Closed

Support empty strings in enums #357

ramnes opened this issue Mar 23, 2021 · 1 comment · Fixed by #358
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers

Comments

@ramnes
Copy link
Contributor

ramnes commented Mar 23, 2021

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
@ramnes ramnes added the 🐞bug Something isn't working label Mar 23, 2021
@dbanty
Copy link
Collaborator

dbanty commented Mar 23, 2021

Ah, interesting bug. We do this to determine whether we should be making a str, Enum or an IntEnum in the generated code. Looks like we need a special case for the empty string included in there. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants