-
Hi, is there an option to give custom types? I want the models to be created in this way. from random_file import UserType
class User(BaseModel):
user_type: Optional[UserType] = Field(None) For the import string I have added it in custom template. I am using jsonschema for generation. Is there a way to specify types like "$schema": http://json-schema.org/draft-07/schema#
type: object
properties:
User:
type: object
properties:
user_type:
type: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 20 replies
-
Hi, There is a similar use case for me. I need to give a function as the default value (the importing part is a similar case here). I am also using jsonschema for generating the models. For examplefoo.py class Foo:
def bar(self):
# code here models.py from foo import Foo
class Baz(BaseModel):
bar = Foo.bar Is there any way to achieve this? |
Beta Was this translation helpful? Give feedback.
-
@gk12277 @balukrishnans And, this is the default template. |
Beta Was this translation helpful? Give feedback.
-
@gk12277 Output I must add a document for |
Beta Was this translation helpful? Give feedback.
@gk12277
I have released a new version
0.11.6
Input
datamodel-code-generator/tests/data/jsonschema/custom_type_path.json
Lines 4 to 9 in 1d5790e
Output
datamodel-code-generator/tests/data/expected/main/main_jsonschema_custom_type_path/output.py
Lines 17 to 23 in 1d5790e
I must add a document for
c…