Skip to content
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

bug: generate_from_file_object doesn't work on file objects without .name attribute #219

Open
VolkerH opened this issue Oct 9, 2023 · 0 comments

Comments

@VolkerH
Copy link

VolkerH commented Oct 9, 2023

The generate_from_file_object function has the arguments
schema_file: FileLikeType and result_file: FileLikeType with FileLikeType = Union[TextIO, TextIOWrapper, FileIO].

However in

schemas_to_render = [SchemaToRender(schema_file, result_file, Path(result_file.name).parent)]

the code tries to access the property .name of result_file. However TextIOBase objects don't have a .name attribute.

Example code like this

schema_file_object = StringIO(json.dumps(Criterion.model_json_schema()))
result_file_object = StringIO()

generate_from_file_object(schema_file=schema_file_object,  result_file=result_file_object)

results in the following error.

\json_schema_for_humans\generate.py:93, in generate_from_file_object(schema_file, result_file, minify, deprecated_from_description, default_from_description, expand_buttons, copy_css, copy_js, link_to_reused_ref, config)
     80 """Generate the JSON schema documentation from opened file objects for both input and output files. The
     81 result_file should be opened in write mode.
     82 """
     83 config = config or get_final_config(
     84     minify=minify,
     85     deprecated_from_description=deprecated_from_description,
   (...)
     90     link_to_reused_ref=link_to_reused_ref,
     91 )
---> 93 schemas_to_render = [SchemaToRender(schema_file, result_file, Path(result_file.name).parent)]
     94 template_renderer = TemplateRenderer(config)
     95 generate_schemas_doc(schemas_to_render, template_renderer)

AttributeError: '_io.StringIO' object has no attribute 'name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant