pydantic-to-typescript icon indicating copy to clipboard operation
pydantic-to-typescript copied to clipboard

Handle Models where Config.extra is not set

Open joe0BAB opened this issue 4 years ago • 0 comments

Hi! First of all, many thanks for providing this useful tool!

I'm trying to get it running, but there are two issues I'm stuck with.

First is the same as #5

The second, when I pass the path of a python file directly I get: `$pydantic2ts --module ./api/apps/folder/models.py --output test.ts --json2ts-cmd ./ui/node_modules/.bin/json2ts 2021-05-11 15:47:53,683 Finding pydantic models... 2021-05-11 15:47:53,688 Generating JSON schema from pydantic models... Traceback (most recent call last): File ".../venv/bin/pydantic2ts", line 8, in sys.exit(main()) File ".../venv/lib/python3.8/site-packages/click/core.py", line 829, in call return self.main(*args, **kwargs) File ".../venv/lib/python3.8/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File ".../venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File ".../venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File ".../venv/lib/python3.8/site-packages/pydantic2ts/cli/script.py", line 222, in main return generate_typescript_defs(module, output, json2ts_cmd) File ".../venv/lib/python3.8/site-packages/pydantic2ts/cli/script.py", line 187, in generate_typescript_defs schema = generate_json_schema(models) File ".../venv/lib/python3.8/site-packages/pydantic2ts/cli/script.py", line 144, in generate_json_schema model_extras = [m.Config.extra for m in models] File ".../venv/lib/python3.8/site-packages/pydantic2ts/cli/script.py", line 144, in model_extras = [m.Config.extra for m in models]

AttributeError: type object 'Config' has no attribute 'extra' ` If I understand the docs correctly, the Config.extra field is optional. However, right now pydantic-to-typescript does not handle this case.

joe0BAB avatar May 11 '21 14:05 joe0BAB