Open gameliee opened 4 months ago
Thank you for the great project.
One thing I would love to be fixed, is that make the project works with Literal data types. Here is a minimal example
Literal
import sys from typing import Literal from pydantic import BaseModel from pydantic_mermaid import MermaidGenerator, Relations class OverdraftInterestRateHistory(BaseModel): """For update history rate""" id: int type: Literal['once', 'freq'] if __name__ == "__main__": current_module = sys.modules[__name__] mg = MermaidGenerator(current_module) chart = mg.generate_chart(relations=Relations.Inheritance) print(chart)
When running the above example, this error raised
$ python test.py Traceback (most recent call last): File "test.py", line 15, in <module> mg = MermaidGenerator(current_module) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\pydantic_mermaid\mermaid_generator.py", line 27, in __init__ self.graph: MermaidGraph = PydanticParser()(module) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\pydantic_mermaid\pydantic_parser.py", line 102, in __call__ graph.service_clients[class_name] = graph.service_clients[class_name] | _get_field_dependencies( File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\pydantic_mermaid\pydantic_parser.py", line 42, in _get_field_dependencies ans |= _get_dependencies(field.type_) File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\pydantic_mermaid\pydantic_parser.py", line 32, in _get_dependencies return {v.__name__} - constrained_types File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\typing.py", line 760, in __getattr__ raise AttributeError(attr) AttributeError: __name__
I would love to contribute, just point me a direction. Thanks.
Oh, I see, the error happens in _get_dependencies. And we do not process this if it is literal. If you can detect literal and then return empty set, I would be happy to merge it.
Thank you for the great project.
One thing I would love to be fixed, is that make the project works with
Literal
data types. Here is a minimal exampleWhen running the above example, this error raised
I would love to contribute, just point me a direction. Thanks.