-
-
Notifications
You must be signed in to change notification settings - Fork 228
null
in an Enum crashes the generator
#500
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
Comments
I think the problem is that NullEnum:
enum:
- "null" The fact that you're getting a traceback is definitely a bug, you should instead get a nicely formatted warning that |
I read around the JSONSchema spec, and it seems like it supports literally any value as an enum. However, I'm not sure how we'd go about doing that in a way that's type safe and idiomatic in Python. I'm going to use this issue to fix the crash & traceback in 0.10.5 and tighten up the parser to fail quick in the event of an enum we don't support. However, if you need Assuming you do need |
@dbanty In the meantime, I was able to quickly work around this issue by changing line 62 of parser/properties/enum_property.py like below: Adding the "if isinstance" bit kept the generator from calling .replace() on a NoneType instead of a str. I don't know if putting None directly into output[sanitized_key] is the right behavior, though. The generation succeeded after that change, but I didn't test the generated client at all. |
Describe the bug
Similar to #357
Client generation fails and gives a Python traceback if an enum like below is present in the generated OpenAPI schema.
To Reproduce
Steps to reproduce the behavior:
output[sanitized_key] = utils.remove_string_escapes(value) if isinstance(value, str) else value
Expected behavior
API client is generated successfully, or an error message is shown about "Failed to parse OpenAPI document" if this enum is invalid.
OpenAPI Spec File
Desktop (please complete the following information):
Additional context
Traceback (most recent call last):
File "/usr/local/bin/openapi-python-client", line 11, in
sys.exit(app())
File "/usr/local/lib/python3.6/site-packages/typer/main.py", line 214, in call
return get_command(self)(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/typer/main.py", line 497, in wrapper
return callback(**use_params) # type: ignore
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/cli.py", line 148, in generate
config=config,
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/init.py", line 329, in create_new_client
config=config,
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/init.py", line 296, in _get_project_for_url_or_path
openapi = GeneratorData.from_dict(data_dict, config=config)
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/openapi.py", line 446, in from_dict
schemas = build_schemas(components=openapi.components.schemas, schemas=schemas, config=config)
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/init.py", line 655, in build_schemas
schemas_or_err = update_schemas_with_data(ref_path=ref_path, data=data, schemas=schemas, config=config)
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/schemas.py", line 93, in update_schemas_with_data
data=data, name=ref_path, schemas=schemas, required=True, parent_name="", config=config
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/init.py", line 627, in property_from_data
name=name, required=required, data=data, schemas=schemas, parent_name=parent_name, config=config
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/init.py", line 532, in _property_from_data
config=config,
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/init.py", line 323, in build_enum_property
values = EnumProperty.values_from_list(enum)
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/parser/properties/enum_property.py", line 62, in values_from_list
output[sanitized_key] = utils.remove_string_escapes(value)
File "/usr/local/lib/python3.6/site-packages/openapi_python_client/utils.py", line 96, in remove_string_escapes
return value.replace('"', r""")
The text was updated successfully, but these errors were encountered: